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
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.
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;
Hi,
Thank you so much for your prompt reply. Could you please explain
infile cards expandtabs truncover;
a little bit?
Best regards,
C
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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.