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

@beginner wrote:

... where would I input the names of columns that I do not want to split into n columns (columns that have the same value for all n entries, for any 1 patient)?



You can add these in the BY statement of the PROC SUMMARY step, e.g.:

by patient age country;
Reeza
Super User

If you're transposing multiple variables, this macro may be of interest.

 

http://www.sascommunity.org/wiki/A_Better_Way_to_Flip_(Transpose)_a_SAS_Dataset

Reeza
Super User

The first step is making the fake data.

In the second steps where they reference faked data, you can reference your data set.

FreelanceReinh
Jade | Level 19

Try this:

data have;
input patient $ fruit $ color $;
cards;
patientA apple  red
patientA banana red
patientA mango  red
patientB apple  blue
patientC cherry green
patientC grape  green
;

proc transpose data=have prefix=fruit_ out=trans(drop=_name_);
by patient color;
var fruit;
run;

proc freq data=have noprint;
tables patient / out=cnt(drop=percent);
run;

data want;
merge trans cnt;
by patient;
run;
      
proc print data=want;
var patient count fruit_: color;
run;
beginner
Calcite | Level 5

Thanks to all for your help!  I haven't been able to try everything you've suggested yet, but the parts I've tried so far are very helpful.  🙂

Ksharp
Super User
data have;
input patient $ fruit $ color $;
cards;
patientA apple  red
patientA banana red
patientA mango  red
patientB apple  blue
patientC cherry green
patientC grape  green
;
proc sql;
 select max(n) into : n separated by ' '
  from (select count(*) as n from have group by patient,color);
quit;
data want;
 set have;
 by patient color;
 array x{*} $ 40 fruit1-fruit&n;
 retain fruit1-fruit&n;
 if first.color then do;n=0;call missing(of x{*});end;
 n+1;
 x{n}=fruit;
 if last.color;
 drop fruit;
run;
 
karthikC
Calcite | Level 5

Hi

 

Just in case if you require only the number of combined rows for the variable Patient ID, below code can be handy.

 

data pat1;

set pat;

if first.patient then count =1;

else  count+1;

if  last.patient;

by 

patient;

run;

for Output, just click on the attachement.  

 

Thanks

 


patient.png

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 21 replies
  • 1739 views
  • 0 likes
  • 5 in conversation