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

I come across it pretty often where I do some work with a dataset in SAS, and want to use that dataset in a different program, but the other program wants the variables in a different format. For instance, I would have a SAS dataset like this:

DATA dataset1;

   INPUT location treatment $ count ;

   DATALINES;

1    Trt1    1

2    Trt1    2

3    Trt1    3

4    Trt1    4

5    Trt1    5

1    Trt2    10

2    Trt2    20

3    Trt2    30

4    Trt2    40

5    Trt2    50

1    Trt3    100

2    Trt3    200

3    Trt3    300

4    Trt3    400

5    Trt3    500

;

proc print data= dataset1;

run;

I want each value of the name variable in this data set to name a new column and the count variable information will be listed under each respective name variable/column . The end result should look like this:

DATA dataset2;

   INPUT location Trt1 Trt2 Trt3;

   DATALINES;

1    1    10    100

2    2    20    200

3    3    30    300

4    4    40    400

5    5    50    500

;

proc print data= dataset2;

run;

Now for small data sets I can rearrange the data by hand, or I can write a macro in Excel to rearrange large data sets. However, is there a way to do this entirely in SAS or convert dataset2 back to dataset1 as well? Doing so would be one less step at least when I need to jump between using data in SAS and another program, so any insight or procedures to look into how to handle this kind of data manipulation would be helpful. I haven't found any specific leads searching yet. Thanks.

1 ACCEPTED SOLUTION
1 REPLY 1

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 695 views
  • 0 likes
  • 2 in conversation