BookmarkSubscribeRSS Feed
srav2
Fluorite | Level 6

Hi,

I'm having a dataset shown as below and all the variables are characters. I need a output in which TERM variable is having the values of both TERM and WORD. PLease help

 

Thanks in advance.

 

INPUT:

 

TERM             WORD                   

Cold                chills                       

Fever              HIgh temperature     

Headache       dizziness                   

                                                        

                                                     

OUTPUT:

                                                        

TERM

 Cold

 chills

  fever

  high temperature

  Headache

 dizziness

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

There are numerous ways to do this and it is fairly easily done, but I have to ask why? This does not make sense to me? 🙂

 

data have;
length TERM $50 WORD $50;
input TERM$ WORD$;
infile datalines dlm=',';
datalines; 
Cold,chills                       
Fever,HIgh temperature     
Headache,dizziness
run; 

data want(keep=TERM);
	set have;
	array vars{*} TERM WORD;
	do i=1 to dim(vars);
		TERM=vars[i];
		output;
	end;
run;
srav2
Fluorite | Level 6

its a question asked in interview.

I tried different ways but couldnt get the result.

 

will try this.

 

srav2
Fluorite | Level 6

thanks a lot it worked..

srav2
Fluorite | Level 6

Could you please explain how this worked out.

Shmuel
Garnet | Level 18

If you are not familiar with arrays, next code is same as @PeterClemmensen's code (but his code is flexible to deal with more than 2 variables):

data want(keep=TERM);
	set have;
	output;   /* original TERM only */
        term = word;
       output;   /* = WORD value */ 
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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