- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This post is really about the @, athough while I am already posting, I might as well ask about the proc means statement, which I am just learning. l am learning from "Learning SAS by Example". There is no solution for this problem in the book, and I do not know why this is not working. Here is the code:
--------------------------------------
Data ReadSpd ;
Input Score @ ;
Do Method = 'A', 'B', 'C' ;
Output ;
End ;
Datalines ;
250 255 256 300 244 268 301 322 256 333
267 275 256 320 250 340 345 290 280 300
350 350 340 290 377 401 380 310 299 399
;
proc print Data=ReadSpd ;
run ;
Title "Mean Read Speeds" ;
proc means mean ;
var Method ;
run ;
--------------------------------
1. The proc print statement only gives me 9 readings, not 30, as it should. When I change the code to read input Score @@ I get 90 readings. Why?
2. How do I get the means for each of the "Speed Readers", which are 'A', 'B'. and 'C'? I want to know what the mean score was for each of the speed readers using the proc means statement.
Thanks a lot for your help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
For some reason, when I rearranged the location of the input text to be within the Do statement, and used @@, now I get 30 readings. I guess the input variables must be within the DO statement?
Do Method = 'A', 'B', 'C' ;
Input Score @@ ;
Output ;
End ;
Datalines ;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The INPUT statement is executable, so where you place it relative to the DO loop makes a big difference. The original code
input score @ ;
do method = 'A', 'B', 'C' ;
output ;
end ;
Is saying read the first value from the line and hold the line for this iteration of the data step. Then output it three times with different values of METHOD. So you only ever read the first score on each line.
Your new code
do method = 'A', 'B', 'C' ;
input score @@;
output ;
end ;
Is telling it to set METHOD to different vlaues and then read the next score from the input and hold the line even across data step interations. So for each pass of the data step you will read three values and assign them to different methods.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@ holds the line you are reading from temporarily, until you reach the end of the statements in the DATA step.
@@ holds the line you are reading from permanently, regardless of whether you reach the end of the statements in the DATA step. The only way to get to the next line is for the INPUT statement to search for another SCORE and, not finding one on the current line, moves on to the next line.
Using all the programs you have tested, you should be able to see this at work. Look at more than the number of observations. Look at the values of the variables in your output data set and you can see these principles at work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Re #2 - you should preferably only ask one question at a time.
Look at the CLASS or BY statement.
If you haven't come across the BY statement I suggest you read up on it, it's an incredibly powerful feature in SAS that's worth learning how to use.
proc sort data=sashelp.class out=class;
by sex;
run;
proc means data=class;
by sex;
var weight height;
run;