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

Hi everyone, I am very new at SAS and am trying to transpose a set of data but having issues.

 

What I have:

UUIDVent_day_0 Vent_day_1 Vent_day_2 Vent_day_3
UU03000110
UU03010011
UU0305.11

 

What I want:

UUIDDayVent_status
UU030000
UU030011
UU030021
UU030030
UU030100
UU030110
UU030121
UU030131
UU03050.
UU030511
UU030521
UU030531

 

I think I am having trouble with the days part. Some of the data is missing and I want to conserve the days (in this case, everyone should have day 0 - day 3 even if data is missing)

Thank you so much in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

data have;
input UUID  $	Vent_day_0	 Vent_day_1	 Vent_day_2	 Vent_day_3	;
cards;
UU0300	0	1	1	0
UU0301	0	0	1	1
UU0305	.	1	1	1 
;

data want;
 set have;
 array v(0:3)  Vent_day_0--Vent_day_3;
 do day=0 to 3;
  Vent_status=v(day);
  output;
 end;
 keep uuid day vent_status;
run;

View solution in original post

4 REPLIES 4
PGStats
Opal | Level 21

How about like this:

 

proc transpose data=have name=day out=want(rename=col1=Vent_status);
by UUID;
var Vent_day_:;
run;

data want;
set want;
day = compress(day,,"kd");
run;

(untested)

PG
novinosrin
Tourmaline | Level 20

data have;
input UUID  $	Vent_day_0	 Vent_day_1	 Vent_day_2	 Vent_day_3	;
cards;
UU0300	0	1	1	0
UU0301	0	0	1	1
UU0305	.	1	1	1 
;

data want;
 set have;
 array v(0:3)  Vent_day_0--Vent_day_3;
 do day=0 to 3;
  Vent_status=v(day);
  output;
 end;
 keep uuid day vent_status;
run;
ghosh
Barite | Level 11
proc transpose out=trans (rename=(COL1=Vent_status));
by uuid;
run;
data want (drop=_NAME_);
  set trans;
  length Day 4;
     Day=put(scan(_name_,-1,'_'),3.);
     ;
 run; 
 proc print;
 run;
 

 Capture.JPG

art297
Opal | Level 21

You already have three good answers, but here is a fourth. It uses the untranspose macro and would really simplify the task if you were untransposing more than one variable.

 

filename ut url 'http://tiny.cc/untranspose_macro';
%include ut ;
%untranspose(data=have, out=want (rename=(day_=Vent_status)),
  by=UUID, prefix=Vent_, id=Day,
  var=day_, missing=yes, var_first=yes)

Art

 

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
  • 4 replies
  • 908 views
  • 4 likes
  • 5 in conversation