BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lillymaginta
Lapis Lazuli | Level 10
data long;
	input enrolid1 date1 : mmddyy10. x1 x2 x3 x4;
	format date1 mmddyy10.;
	datalines;
4 5/5/2009    y n y n
4 5/5/2009    y y y y;
run; 

data wide;
input variable def
datalines;
x1   head
x2   neck
x3   stomach
x4    colon;
run; 

I have the following datasets, I am trying to define each of the xs in data long from data wide and looking for the following output : 

enrolid1 date1 head neck stomach colon 

4 5/5/2009 y n y n

4 5/5/2009 y y y y

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Just rename the variable name .

 

data long;
	input enrolid1 date1 : mmddyy10. (x1 x2 x3 x4) ($);
	format date1 mmddyy10.;
	datalines;
4 5/5/2009    y n y n
4 5/5/2009    y y y y
;
run; 

data wide;
input variable $ def $;
datalines;
x1   head
x2   neck
x3   stomach
x4    colon
;
run; 

proc sql noprint;
select catx('=',variable,def) into : list separated by ' '
 from wide;
quit;
proc datasets library=work nolist nodetails;
modify long;
rename &list ;
quit;

View solution in original post

3 REPLIES 3
Ksharp
Super User

Just rename the variable name .

 

data long;
	input enrolid1 date1 : mmddyy10. (x1 x2 x3 x4) ($);
	format date1 mmddyy10.;
	datalines;
4 5/5/2009    y n y n
4 5/5/2009    y y y y
;
run; 

data wide;
input variable $ def $;
datalines;
x1   head
x2   neck
x3   stomach
x4    colon
;
run; 

proc sql noprint;
select catx('=',variable,def) into : list separated by ' '
 from wide;
quit;
proc datasets library=work nolist nodetails;
modify long;
rename &list ;
quit;
novinosrin
Tourmaline | Level 20

Hello @lillymaginta 

 

The question isn't making a clean sense of a clear logical objective of a look up.  But,FWIW

 


data wide;
input variable $ def $;
datalines;
x1   head
x2   neck
x3   stomach
x4    colon
;
run;

proc transpose data=wide out=t(drop=_name_);
var variable;
id def;
run;

data want;
set long;
if _n_=1 then set t;
array j head--colon;
array k x:;
do i=1 to dim(j);
j(i)=k(i);/*I am not sure if this is what you want, the look up flow should be rather neat */
end;
drop i x:;
run;
lillymaginta
Lapis Lazuli | Level 10
Thank you, I was trying to replace the variables with the correct names as Ksharp suggested

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 732 views
  • 2 likes
  • 3 in conversation