- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
--------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
--------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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
--------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.