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

From the helpful post: Writing data from a matrix to a SAS data set - The DO Loop

It shows to make a dataset from vectors with the var statement.

proc iml;

/** create SAS data set from vectors **/

y = {1,0,3,2,0,3}; /** 6 x 1 vector **/

z = {8,7,6,5,6}; /** 5 x 1 vector **/

c = {A A A B B B}; /** 1 x 6 character vector **/

create MyData var {y z c}; /** create data set **/

append; /** write data in vectors **/

close MyData; /** close the data set **/

And from a matrix with the from statement.

proc iml;

/** create SAS data set from a matrix **/

x = {1 2 3,

  4 5 6,

  7 8 9,

  3 2 1 }; /** 4 x 3 matrix **/

create MyData2 from x[colname={"q" "r" "s"}];

append from x;

close MyData2;

Say I have 2 vectors with dimensions, 5x1, and a matrix size 5 x 5.  What is the best way combine or just utilize one of these approaches to get a SAS dataset with 5 records and 7 columns? Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

If they are all the same data type (all numeric or all character), I would use concatenation:
x = {1,2,3,4,5};

y = {5,4,3,2,1};

z = shape(1:25, 5);

m = x || y || z;

create MyData from m;

append from m;

close;

View solution in original post

2 REPLIES 2
Rick_SAS
SAS Super FREQ

If they are all the same data type (all numeric or all character), I would use concatenation:
x = {1,2,3,4,5};

y = {5,4,3,2,1};

z = shape(1:25, 5);

m = x || y || z;

create MyData from m;

append from m;

close;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 2 replies
  • 2004 views
  • 0 likes
  • 2 in conversation