BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ybz12003
Rhodochrosite | Level 12

Hello,

I'm wondering if I could get the Dataout_CNT and Dataout_PCT results from Datain.   I tried the proc transpose, my codes didn't work.  Maybe I didn't get the correct ones.

data dataIN;
   infile datalines dsd;
   input PT_class : $50. Dema  : $100. CNT PCT;
   datalines;
	ED_RSV_Pos,0_Neg5 months,100,20
	ED_RSVH,0_Neg5 months,200,35
	IPT_RSV_Pos,0_Neg5 months,400,30
	IPT_RSV_Neg,0_Neg5 months,1000,45
	ED_RSV_Pos,12_Neg23 months,100,20
	ED_RSV_Neg,12_Neg23 months,200,35
	IPT_RSV_Pos,12_Neg23 months,400,30
	IPT_RSV_Neg,12_Neg23 months,1000,45
	ED_RSV_Pos,6_Neg11 months,100,20
	ED_RSV_Neg,6_Neg11 months,200,35
	IPT_RSV_Pos,6_Neg11 months,400,30
	IPT_RSV_Neg,6_Neg11 months,1000,45
	ED_RSV_Pos,24_Neg59 months,100,20
	ED_RSV_Neg,24_Neg59 months,200,35
	IPT_RSV_Pos,24_Neg59 months,400,30
	IPT_RSV_Neg,24_Neg59 months,1000,45
	ED_RSV_Pos,Female,100,20
	ED_RSV_Neg,Female,200,35
	IPT_RSV_Pos,Female,400,30
	IPT_RSV_Neg,Female,1000,45
	ED_RSV_Pos,Male,100,20
	ED_RSV_Neg,Male,200,35
	IPT_RSV_Pos,Male,400,30
	IPT_RSV_Neg,Male,1000,45
;

Data dataout_CNT;
	infile datalines dsd;
   input Dema : $100.  ED_RSV_Pos  ED_RSV_Neg  IPT_RSV_Pos  IPT_RSV_Neg ;
   datalines;
	0_Neg5 months,100,200,400,1000
	6_Neg11 months,100,200,400,1000
	12_Neg23 months,100,200,400,1000
	24_Neg59 months,100,200,400,1000
	Female,100,200,400,1000
	Male,100,200,400,1000
;

Data dataout_PCT;
	infile datalines dsd;
   input Dema : $100.  ED_RSV_Pos  ED_RSV_Neg  IPT_RSV_Pos  IPT_RSV_Neg ;
   datalines;
	0_Neg5 months,20,35,30,45
	6_Neg11 months,20,35,30,45
	12_Neg23 months,20,35,30,45
	24_Neg59 months,20,35,30,45
	Female,20,35,30,45
	Male,20,35,30,45
;
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Didn't work is awful vague.

Are there errors in the log?: Post the code and log in a code box opened with the "</>" to maintain formatting of error messages.

No output? Post any log in a code box.

Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the "</>" icon or attached as text to show exactly what you have and that we can test code against.

 

You don't even show what your code looked like. However when you show two different values with the same variable names it would not happen with a single proc transpose.

Your output does not show what you expect to do with the ED_RSVH values. Were those even considered?

 

Try this. If this is sufficient it should be workable pattern for the second set.

proc sort data=datain;
   by dema pt_class;
run;
proc transpose data=datain (where=(Pt_class ne'ED_RSVH'))
   out=dataout_cnt (drop=_name_);
  by dema;
  id PT_class;
  var cnt;
run;

View solution in original post

1 REPLY 1
ballardw
Super User

Didn't work is awful vague.

Are there errors in the log?: Post the code and log in a code box opened with the "</>" to maintain formatting of error messages.

No output? Post any log in a code box.

Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the "</>" icon or attached as text to show exactly what you have and that we can test code against.

 

You don't even show what your code looked like. However when you show two different values with the same variable names it would not happen with a single proc transpose.

Your output does not show what you expect to do with the ED_RSVH values. Were those even considered?

 

Try this. If this is sufficient it should be workable pattern for the second set.

proc sort data=datain;
   by dema pt_class;
run;
proc transpose data=datain (where=(Pt_class ne'ED_RSVH'))
   out=dataout_cnt (drop=_name_);
  by dema;
  id PT_class;
  var cnt;
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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