Please help me in explaning the answer of following program.
data a;
input id;
cards;
1
2
3
4
;
run;
data b;
set a;
id1=id;
output;
id2=id;
output;
id3=id;
output;
run;
Hi:
I am not sure what you are looking for when you ask for an ANSWER to your program. In the first program, you read 4 observations and WORK.A has 4 observations and 1 variable or column called ID, as shown in the screen shot below. Your program that creates WORK.B has 3 explicit OUTPUT statements and makes 3 new variables, ID1, ID2, and, ID3. There are no controls in the program to restrict when OUTPUT occurs, so for EVERY observation in WORK.A, you will write 3 observations into WORK.B, for a total of 12 observations, as shown below. The variables in WORK.B are ID, ID1, ID2 and ID3, but for every row, the values are the same as for the original value of ID, so if you look at the PROC PRINT for WORK.B you will see that observations 1-3 are all for ID=1; observations 4-6 are all for ID=2; observations 7-9 are for ID=3 and observations 10-12 are for ID=4. I suspect this is not what you want.
The program is working as written, so there is nothing to ANSWER. Is there something wrong with the output as shown in WORK.B? Did you need some other structure to the data.
I wonder whether you wanted something more like this:
Where the 4 observations from WORK.A were restructured to be only 1 observation with numbered values that corresponded to the original values from WORK.A (so ID1=1, ID2=2, etc).
There are 2 ways to restructure WORK.A -- one is to use PROC TRANSPOSE and the other is to use a DATA step program.
cynthai
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.