Say I want to create a dataset (manually by hard coding each value) looking like this:
Column1 Column2 Column3
1 2 3
4 5 6
How would I do this?
This is trivial to do in for instance Python, R or MATLAB. But I do not know how to do this in SAS. Any suggestions?
Thanks.
Is this what you mean by trivial?
data want;
input column1-column3;
datalines;
1 2 3
4 5 6
run;
Or maybe you are actually looking for:
data want;
column1=1; column2=2; column3=3; output;
column1=4; column2=5; column3=6; output;
run;
Is this what you mean by trivial?
data want;
input column1-column3;
datalines;
1 2 3
4 5 6
run;
Or maybe you are actually looking for:
data want;
column1=1; column2=2; column3=3; output;
column1=4; column2=5; column3=6; output;
run;
One slight correction:
data want;
input column1-column3;
datalines;
1 2 3
4 5 6
;
Terminate the DATALINES block with a single semicolon on its own line. The RUN statement afterwards is optional.
@Kurt_Bremser wrote:
One slight correction:
data want; input column1-column3; datalines; 1 2 3 4 5 6 ;
Terminate the DATALINES block with a single semicolon on its own line. The RUN statement afterwards is optional.
True, the naked semi-colon is a bit more terse, which I think is important to the OP. But I've never been a fan of using it, since run; works both for this, and for data steps that don't use the datalines; statement.
The documentation of the DATALINES statement is quite specific:
Use a null statement (a single semicolon) to indicate the end of the input data.
So one must not be surprised if the "run" becomes part of the input data sometime in the future.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.