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

Hello everyone,

 

I have a dataset with multiple columns but they are essentially two numeric variables (Score and Measure). I need to reformat the dataset into one that only contains these two variables. Thank you very much in advance!

 

data example;

input score1 measure1 score2 measure2 score3 measure3;

datalines;

0 5.678922 3 4.666666 6 3.555555

1 5.123456 4 4.234567 7 2.888888

2 4.999999 5 3.876543 8 1.555555

;

 

data want;

input score measure;

datalines;

0 5.678922 

1 5.123456 

2 4.999999  

3 4.666666

4 4.234567

5 3.876543

6 3.555555

7 2.888888

8 1.555555

;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
japelin
Rhodochrosite | Level 12

try this code.

data want;
  set example;
  length score measure 8;
  array sc{3} score1-score3;
  array ms{3} measure1-measure3;
  do i=1 to dim(sc);
    score=sc{i};
    measure=ms{i};
    output;
  end;
  drop i score1-score3 measure1-measure3;
run;

proc sort data=want;
  by score;
run;

View solution in original post

3 REPLIES 3
japelin
Rhodochrosite | Level 12

try this code.

data want;
  set example;
  length score measure 8;
  array sc{3} score1-score3;
  array ms{3} measure1-measure3;
  do i=1 to dim(sc);
    score=sc{i};
    measure=ms{i};
    output;
  end;
  drop i score1-score3 measure1-measure3;
run;

proc sort data=want;
  by score;
run;
ballardw
Super User

If you don't really have other information it might be that you could read the source file differently:

 

data example;
input score measure @@;
datalines;
0 5.678922 3 4.666666 6 3.555555
1 5.123456 4 4.234567 7 2.888888
2 4.999999 5 3.876543 8 1.555555
;

The @@ used here means in effect "keep using the same input variables until you run out of data".

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

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 4599 views
  • 2 likes
  • 3 in conversation