BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
RAVI2000
Lapis Lazuli | Level 10

Hi all,
Looking to manage my data.

 

HAVE:

RAVI2000_0-1656439188605.png


want:

RAVI2000_1-1656439217837.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Please explain:

 

  1. What happened to trt 1 subject 1 in your output?
  2. Why are some cells in the output blank and others have a dash?

Other than those issues, this is really just a PROC TRANSPOSE with BY statement — although depending on what analysis you will do next, you might want to leave the data un-transposed. So what analysis are you going to do next?

 

UNTESTED CODE

 

proc transpose data=have out=want;
    by trt subject;
    var grade;
    id test;
run;

Then you can turn the zeros into spaces or dashes as desired.

 

If you want tested code, and for all questions you might ask in the future, we cannot use data in a screen capture. Provide data as SAS data step code, which you can type yourself, or you can follow these instructions. Consider this mandatory in the future, data only as SAS data step code, not screen captures, not Excel files.

--
Paige Miller

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

Please explain:

 

  1. What happened to trt 1 subject 1 in your output?
  2. Why are some cells in the output blank and others have a dash?

Other than those issues, this is really just a PROC TRANSPOSE with BY statement — although depending on what analysis you will do next, you might want to leave the data un-transposed. So what analysis are you going to do next?

 

UNTESTED CODE

 

proc transpose data=have out=want;
    by trt subject;
    var grade;
    id test;
run;

Then you can turn the zeros into spaces or dashes as desired.

 

If you want tested code, and for all questions you might ask in the future, we cannot use data in a screen capture. Provide data as SAS data step code, which you can type yourself, or you can follow these instructions. Consider this mandatory in the future, data only as SAS data step code, not screen captures, not Excel files.

--
Paige Miller
RAVI2000
Lapis Lazuli | Level 10

Thank you @PaigeMiller for the input.
I would only like to populate values who have grades. For the trt 1, there are no grades.
I have used the above code and It is giving me like below:


RAVI2000_0-1656440380474.png

 

PaigeMiller
Diamond | Level 26

Please provide the data as SAS data step code, as I requested.


Also, please show the exact code you used.

--
Paige Miller
RAVI2000
Lapis Lazuli | Level 10
data have;
input trt subject test 3$ grade;
cards;
1 1  ALT  0
1 1  AST  0
1 1  BILI 0
1 1  GGT  0
1 3  ALT  0
1 3  AST  0
1 3  BILI 1
1 3  GGT  2
2 4  ALT  1
2 4  AST  0
2 4  BILI 0
2 4  GGT  0
2 5  ALT  0
2 5  AST  2
2 5  BILI 0
2 5  GGT  3
3 6  ALT  0
3 6  AST  0
3 6  BILI 0
3 6  GGT  1
3 10 ALT  0
3 10 AST  4
3 10 BILI 1
3 10 GGT  0
;
run;
RAVI2000
Lapis Lazuli | Level 10
proc transpose data = have out=want prefix=_;
by trt subject test descending grade;
var grade;
id test;
run;
PaigeMiller
Diamond | Level 26

@RAVI2000 wrote:
proc transpose data = have out=want prefix=_;
by trt subject test descending grade;
var grade;
id test;
run;

That's not the code I provided. In fact the code I provided seems to work perfectly on your data.

--
Paige Miller

sas-innovate-2024.png

Available on demand!

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

 

Register now!

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.

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
  • 6 replies
  • 359 views
  • 1 like
  • 2 in conversation