BookmarkSubscribeRSS Feed
CynthiaWei
Obsidian | Level 7

Hi SAS Pros,

 

I have a data with a set of variables: drug1, drug2, drug3, ... until drug80. I am listing some of them right now.

 

Have:

drug1 drug2 drug3 drug4 drug5 drug6 drug7 drug8
a c e i b d h n
b c e g h      
a b d h j k l o
b d h j k      
h i j k        
u v            
x w y z        

 

Want: I want to print out all the drugs that in the above, like a drug list.

drug_list
a
b
c
d
e
g
h
i
j
k
l
n
o
u
v
w
x
y
z

 

Thank you in advance for any help!

 

Best regards,

 

C

4 REPLIES 4
PaigeMiller
Diamond | Level 26

PROC TRANSPOSE to make the data long, with all of your values in one column; then PROC SQL with the DISTINCT option to get all values that exist in your data set.

--
Paige Miller
novinosrin
Tourmaline | Level 20

Hi @CynthiaWei  Spice up with Hashes for some fun

 


data have;
infile cards expandtabs truncover;
input (drug1	drug2	drug3	drug4	drug5	drug6	drug7	drug8 ) ($);
cards;
a	c	e	i	b	d	h	n
b	c	e	g	h	 	 	 
a	b	d	h	j	k	l	o
b	d	h	j	k	 	 	 
h	i	j	k	 	 	 	 
u	v	 	 	 	 	 	 
x	w	y	z	 	 	 	 
;


data want;
 if _n_=1 then do;
   dcl hash H () ;
   h.definekey  ("drug") ;
   h.definedata ("drug") ;
   h.definedone () ;
 end;
 set have;
 array t drug1-drug8;
 do over t;
  drug=t;
  if h.check()=0 or  missing(drug) then continue;
  output;
  h.add();
 end;
 keep drug;
run;

 
CynthiaWei
Obsidian | Level 7

Hi,

 

Thank you so much for your prompt reply. Could you please explain 

infile cards expandtabs truncover;

a little bit?

 

Best regards,

 

C

novinosrin
Tourmaline | Level 20

 

your sample seemed to have TAB chars between values, so the EXPANDTABS. TRUNCOVER is like MISSOVER to account for missing values in your sample. 

 


@CynthiaWei wrote:

Hi,

 

Thank you so much for your prompt reply. Could you please explain 

infile cards expandtabs truncover;

a little bit?

 

Best regards,

 

C


 

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1302 views
  • 0 likes
  • 3 in conversation