Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 01-20-2015 01:22 PM
(1178 views)

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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;

2 REPLIES 2

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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;

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thanks Rick!

**Available on demand!**

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

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.