data macpro.bimodels_type;
infile datalines ;
input Model & $ model_class$ model_price model_frame$ DOpurchase;
*length Model$20. model_class$25. model_price4. ;
datalines;
Black Bora Track 796 Aluminum 01Aug2009
Delta Breeze Road 400 CroMoly 23Aug2010
Jet Stream Track 1160 CroMoly 01Aug2009
Mistral Road 1995 Carbon Comp 01Jul2010
Nor'easter Mountain 900 Aluminum 05Jul2010
Santa Ana Mountain 459 Aluminum 20Jul2010
Scirocco Mountain 2300 Titanium 08Sep2011
Trade Wind Road 759 Aluminum 08Sep2011
in Model variable i where trying to fix blank, i used & syntax like input Model & $ and so on... but i can't able to fix Black Bora in single column. how i can fix this.
You cannot change the length of a character variable after SAS has already determined what it will be. I find it much easier to get it right if I explicitly define the variables before using them in other statements.
data bimodels_type;
infile datalines truncover ;
length Model $20 model_class $25 model_price 8 model_frame $20 DOpurchase 8 ;
format DOpurchase date9. ;
input Model & model_class model_price model_frame & DOpurchase :date.;
datalines;
Black Bora Track 796 Aluminum 01Aug2009
Delta Breeze Road 400 CroMoly 23Aug2010
Jet Stream Track 1160 CroMoly 01Aug2009
Mistral Road 1995 Carbon Comp 01Jul2010
Nor'easter Mountain 900 Aluminum 05Jul2010
Santa Ana Mountain 459 Aluminum 20Jul2010
Scirocco Mountain 2300 Titanium 08Sep2011
Trade Wind Road 759 Aluminum 08Sep2011
;
For the & modifier to work you need to have at least two spaces (delimiters actually) after the value and before the next value. So in your data the fourth line is going to have a problem since there are not two spaces before the date.
You could either fix the input data.
Mistral Road 1995 Carbon Comp 01Jul2010
Or if you know that every record will have a date you could read it as part of the previous character variable and then take it back out.
data bimodels_type;
infile datalines truncover ;
length Model $20 model_class $25 model_price 8 model_frame $50 DOpurchase 8 ;
format DOpurchase date9. ;
input Model & model_class model_price model_frame $50.;
DOpurchase=input(scan(model_frame,-1,' '),date11.);
model_frame = substr(model_frame,1,length(model_frame)-9);
datalines;
Black Bora Track 796 Aluminum 01Aug2009
Delta Breeze Road 400 CroMoly 23Aug2010
Jet Stream Track 1160 CroMoly 01Aug2009
Mistral Road 1995 Carbon Comp 01Jul2010
Nor'easter Mountain 900 Aluminum 05Jul2010
Santa Ana Mountain 459 Aluminum 20Jul2010
Scirocco Mountain 2300 Titanium 08Sep2011
Trade Wind Road 759 Aluminum 08Sep2011
;
If you are indeed trying to wrap your code containing datalines inside a macro (as the title suggests), this won't work. Datalines/cards are statements that cannot be executed within a macro. As an alternative, you may save your datalines in a text file and read in that file, which works within macro code.
Related
I have a dataset that looks like this in Tableau.
Name Subject Grade
Mina Math 28
English 92
Science 10
Bill Math 19
English 10
Science 38
Kay Math 39
English 92
Science 83
I need the data to look like this
Name Math English Science
Mina 28 92 10
Bill 19 10 38
Kay 39 92 83
How can I do this in Tableau? I am assuming I need to create a calculated field. Just not sure how to approach this as I am a beginner.
As Alex Blakemore suggested, you could pivot your entire dataset in the data source page itself, but I am assuming the first view you have is a Worksheet with Name, Subject, Grade fields in columns of the worksheet, and you would like to present your data as in the second view without modifying your data source.
It's possible by creating three calculated fields:
Math:
IF [Subject] = "Math" THEN [Grade] END
English:
IF [Subject] = "English" THEN [Grade] END
Science:
IF [Subject] = "Science" THEN [Grade] END
Now try dragging Name, Math, English and Science fields into the columns of the Tableau Worksheet and you should be able to get what you need without actually pivoting your data source itself. Hope this helps!
I have a table of tennis players. On Tableau I'm trying to plot number of players from each country. The table looks like below. I'm unable to use 'bin' as it seems to work for only numerical data. How do I go about this?
Pla_ID Country_ Code
200001 SUI
200002 IND
200003 USA
200004 ITA
200005 USA
200006 USA
200007 ITA
200008 SUI
200009 SUI
200010 SUI
200011 CRO
200012 RUS
200013 RUS
200014 FRA
I have some data that summarizes unit count by week by year. IOW's, my datatable looks like this:
Week/ 2012/ 2013/ 2014/ 2015
1/ 45/ 45/ 31/ 28
2/ 45/ 52/ 54/ 58
3/ 40/ 42/ 62/ 51
4/ 41/ 50/ 58/ 50
5/ 43/ 46/ 58/ 46
6/ 41/ 49/ 56/ 56
...and so on (sorry about the formatting). I am displaying this data in a Google Line Chart - multiple lines, one line for each year. My challenge is: how to display (alpha) months on the x-axis of the line chart? (Currently I get week numbers, which don't mean much to anyone!)
SEE COMMENTS BELOW FOR ANSWER
If your starting point is a dataset with "by week" data you wont be able to use it for displaying monthly data. Not accurately anyway.
What you really want to do is to change your query so as to get a dataset with monthly data.
I have the following data representing values over a 12 month period:
1. 0
2. 253
3. 168
4. 323
5. 556
6. 470
7. 225
8. 445
9. 98
10. 114
11. 381
12. 187
How can I smooth this line forward?
What I need is that going through the list sequentially any value that is above the mean (268) be evenly distributed amongst the remaining months- but in such a way that it produces as smooth a line as possible. I need to go through from Jan to Dec in order. Looking forward I want to sweep any excess (peaks) into the months still to come such that the distribution is as even as possible (such that the troughs are filled first). So the issue is to, at each point, determine what the "excess" for that month is and secondly how to distribute that amongst the months still to come.
I have used
p = find(Diff>0);
n = find(Diff<=0);
POS = Diff(p,1);
NEG = Diff(n,1)
to see where shortfall/ excesses against the mean exist but unsure how to construct a code that will redistribute forward by allocating to the "troughs" of the distribution first. An analogy is that these numbers represent harvest quantities and I must give out the harvest to the population. How do I redistribute the incoming harvest over the year such that I minimise excess supply/ under supply? I obviously cannot give out anything I haven't received in a particular month unless I have stored some harvest from previous months.
e.g. I start in Jan, I see that I cannot give anything to the months Feb to Dec so the value for Jan is 0. In Feb I have 253- do I adjust 253 downwards or give it all out? If so by how much? and where do I redistribute the excess I trim between Mar to Dec? And so on and so forth.. How do I do this to give as smooth (even) a distribution as possible?
For any month the new value assigned to that month cannot exceed the current value. The sum for the 12 months must be equal before and after smoothing. As the first position January will always be 0.
Simple version, just loops through and if the next month is lower than the current month, passes value forward to equalise them.
for n = 1:11
if y(n)>y(n+1);
y(n:n+1)=(y(n)+y(n+1))/2;
end
end
It's not very clear to me what you're asking...It sounds a bit like a roundabout way of asking how to fit a straight line to data. If that is the case, see below. Otherwise: please clarify a bit more what you want. Provide a toy example input data, and expected output data.
y = [ 0 253 168 323 556 470 225 445 98 114 381 187 ].';
x = (0:numel(y)-1).';
A = [ones(size(x)) x];
plot(...
x, y, 'b.',...
x, A*(A\y), 'r')
xlabel('Month'), ylabel('Data')
legend('original data', 'fit')
I dont get exactly what you want either, maybe something simple like this?
year= [0 253 168 323 556 470 225 445 98 114 381 187];
m= mean(year);
total_before = sum(year)
linear_year = linspace(0,m*2,12);
toal_after= sum(linear_year)
this gives you a line, the sum stays the same and the line is perfectly smooth ...
I am newly disgnosed with high blood pressure and need to a) check my bp regularly now and keep a log of it and b) take medicine. You can't help me with b), but I'd need your kind help with a).
I need to keep a log of my blood pressure, therefore I need to take a few readings each day. My log looks like this:
20121001 0801 175 101
20121001 0802 Pill
20121001 1017 125 91
20121001 1537 121 101
20121001 1907 117 89
20121002 0758 191 111
20121002 0759 Pill
20121002 1003 117 98
(...)
Could you help me out with a gnuplot config file that reads the above two datapoints, plots them against the time (%Y%m%d %H%M).
The caveat here is the lines "... Pill" which I'd like to show up on the plot as a dot, a vertical line or something similar (they simply show when I have taken my pill).
Also, and I'm not quite sure if this is possible, I'd like to visualize the difference between datapoint 1 and datapoint 2, ie. 175-101=74 in the first line.
This would tremendously help me in visualizing if (and if yes, when) my pills start working.
Thank you!
I created the following bash script. Run it with your log file name as the argument:
#! /bin/bash -e
input=$1
start=$(head -n1 "$input")
start=${start:0:9}0000
end=$(tail -n1 "$input")
end=${end:0:9}2359
gnuplot <<EOF
set terminal png
set output 'bp.png'
set xdata time
set timefmt '%Y%m%d %H%M'
set xrange ['$start':'$end']
plot '< grep -v Pill "$input"' using 1:(\$3-\$4):3:4 with errorbars pt 2 title 'Pressure', \
'< grep Pill "$input"' using 1:(100) with points lw 2 pt 7 title 'Pill'
EOF
(($?)) && exit 1
display bp.png
I will answer the second part of your question. Therefor, I updated your file to have something to log.
1 20121001 0801 175 101
2 20121001 0802 Pill
3 20121001 1017 125 91
4 20121001 1537 121 101
5 20121001 1907 117 89
6 20121002 0758 191 111
7 20121002 0759 Pill
8 20121002 1003 117 98
The gnuplot script looks like this
plot "< grep -v Pill meas2" using 1:($4-$5) with line, \
"< grep Pill meas2" using 1:($2*0) ps 10 pt 8
Where the inputlines not containing Pill are selected. You can use $4-$5 to perform the calculation. The other plot plots a symbol at the horizontal axis on the times where pill is in the line.
For the first part, I found some hints: http://t16web.lanl.gov/Kawano/gnuplot/datetime-e.html