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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.