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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

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