Hi all,
I am attempting to read in the results2.data data set so that it looks like the below output. However, when I try to I get an output that has the 4 variables below but only has values for source, and the values are 11, 11, 22,
The data residing in the results2.dat raw data file came from two different sources (1 and 2). If the value in column 10 is 1, the data in that record came from source 1. If the value in column 10 is 2, the data in that record came from source 2. In short, your job is to read the data file into a SAS data set called results2, so that when printed it looks like this:
In order to do this, you'll need to:
Then, print the resulting SAS data set.
DATA results2;
input dummy :$6. dummy :$6. source @;
if source=1 then input @1 id name $ source score;
else if source=2 then input @1 id score source name $;
drop dummy ;
DATALINES;
11 john 1 77
11 88 2 james
22 bobby 1 55
22 89 2 opey
RUN;
You also could push (and hold) the pointer at column 1 in the first input. Then the subsequent input's don't need the "@1".
DATA results2;
input dummy :$6. dummy :$6. source @1 @;
if source=1 then input id name $ source score;
else if source=2 then input id score source name $;
drop dummy ;
DATALINES;
11 john 1 77
11 88 2 james
22 bobby 1 55
22 89 2 opey
RUN;
We can't see the example data. Copy some rows using a plain text editor and paste into a code box on the forum opened using the {I} icon.
You can use a trailing @ sign to hold the buffer on an input statement:
input source 10 @;
so you could use the value of source for different input statements:
if source = 1 then input <what ever is needed>;
else if source=2 then input <the other info>;
The details of the input are up to you.
Sorry, this is the data set:
DATA results2;
input dummy :$6. dummy :$6. source @;
if source=1 then input @1 id name $ source score;
else if source=2 then input @1 id score source name $;
drop dummy ;
DATALINES;
11 john 1 77
11 88 2 james
22 bobby 1 55
22 89 2 opey
RUN;
You also could push (and hold) the pointer at column 1 in the first input. Then the subsequent input's don't need the "@1".
DATA results2;
input dummy :$6. dummy :$6. source @1 @;
if source=1 then input id name $ source score;
else if source=2 then input id score source name $;
drop dummy ;
DATALINES;
11 john 1 77
11 88 2 james
22 bobby 1 55
22 89 2 opey
RUN;
That worked, thank you for your help.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.