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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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