BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Curious4
Fluorite | Level 6

I am trying to figure out wha this part of this question is asking "Then use statements a data set with variables year and yield. Specify the year; set yield equal to the variable then use an output statement to put the variable on a single line. Also get rid of most of the missing values by using an if statement with the output (for ex: if y1980 ne . then output;)c. use the following code to summarize the data"

 

so far I have 

data barley;
infile "/folders/myfolders/DATASETS/barley.txt" dlm='09'x firstobs=15 expandtabs;
input obs y1980 y1982 y1986;
 
 

Question I am referring to 

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

Instead of asking me - what does your output look like?  Does it match what you want?

 

The problem you linked to says "specify year, set yield equal to the variable then use an output statement".  While it's true you have three output statements, you don't specify the year value.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

View solution in original post

6 REPLIES 6
mkeintz
PROC Star

It's worded awkwardly, but it is essentially saying to take each observation with three values (yields for 1980, 1982, and 1986)  and convert to three observations with two variables:  year and yield.  YEAR would only have the values 1980, 1982, and 1986.  The resulting dataset would have 3 times the number of observations as the starting dataset  (excluding missing values, if you so choose).   You then could use the YEAR variable as a classification variable, or as an easy way to look at subsets.

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Curious4
Fluorite | Level 6

I still am confused about what this means.

mkeintz
PROC Star

It means to take this data set (have1), which you already know how to make.  (I use a sample of only the first 3 observations from your data):

 

data have1;
  input OBS y1980 y1982 y986;
datalines;
1 211 192 149
2 221 179 132
3 225 134 206
run;
proc print;
run;

And make it to look like this:

data have2;
  input OBS @;
  do year=1980,1982,1986 ;
    input yield @;
	output;
  end;
datalines;
1 211 192 149
2 221 179 132
3 225 134 206
run;
proc print;
run;

Take a look at the results of the proc prints.  The second one has nine lines, one for each obs/year combination.  

 

But instead of making have2 from the original raw data, as I have done above, they want you to make have2 from have1, in a data step program.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Curious4
Fluorite | Level 6
data barley;
infile "/folders/myfolders/DATASETS/barley.txt" dlm='09'x firstobs=15 expandtabs;
input obs y1980 y1982 y1986;
Y=y1; group=1; output;
Y=y2; group=2; output;
Y=y3; group=3; output;


I did this so far. Does this look like the right track?
mkeintz
PROC Star

Instead of asking me - what does your output look like?  Does it match what you want?

 

The problem you linked to says "specify year, set yield equal to the variable then use an output statement".  While it's true you have three output statements, you don't specify the year value.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Curious4
Fluorite | Level 6
okay, thanks.

I think i figured it out.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1850 views
  • 0 likes
  • 2 in conversation