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

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. 

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

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;

 

--------------------------
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

4 REPLIES 4
mkeintz
PROC Star

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;

 

--------------------------
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

--------------------------
Kurt_Bremser
Super User

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.

mkeintz
PROC Star

@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 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

--------------------------
Kurt_Bremser
Super User

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.

SAS Innovate 2025: Register Now

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!

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
  • 4 replies
  • 5221 views
  • 3 likes
  • 3 in conversation