Hi,
I have a dataset with drug codes (rxcode_1) and their corresponding drug names (erxname1). Some of the drug names are missing in my dataset although I have the codes, and I am trying to manually input in the appropriate name. I had been manually doing in the Excel dataset and then reimporting into SAS, but I know there must be a more efficient way to do in SAS. I tried a label statement which did not work. Please advise. Thanks in advance!
For instance, in example below, rxcode_1=9347410 is missing its erxname1 in my dataset and needs to be labeled citalopram:
rxcode_1 erxname1
333 lexapro
333 lexapro
9347410
333 lexapro
Without more information (like how the two variables are formatted, etc), its a little difficult to give an exact answer for you situation.
But I created a dummy table where both fields are character formatted.
DATA WORK.HAVE;
FORMAT rxcode_1 $10. erxname1 $20. ;
INFORMAT rxcode_1 $10. erxname1 $20. ;
INPUT rxcode_1 erxname1;
INFILE DATALINES DLM='|' DSD;
DATALINES;
333|lexapro
333|lexapro
9347410|
333|lexapro
;
With this table, the following logic can be used to fill the blank value where the rxcode_1 = '9347410':
DATA WORK.WANT;
SET WORK.HAVE;
IF rxcode_1='9347410' THEN erxname1='citalopram';
RUN;
Final output table results:
rxcode_1 erxname1 333 lexapro 333 lexapro 9347410 citalopram 333 lexapro
Hope this helps.
If you already have a data set with all of the codes and names one of the easiest approaches might be to make a format using that data set. Following is a brief example. The first data step it just to make something that may be a bit like your data set of codes and drugs. The Second data step provides variables that are needed to create a format using the Cntlin option on proc format, then create the format. The last shows one way to use the format. You could either use it conditionally to only replace missing names, or use unconditionally to replace all entered names (which has the advantage of addressing certain issues with manual data entry such as correcting spelling or capitalization). Or alternatively ignore the name variable and assign the format to the code variable.
Data codes; input code $ name $; datalines; 333 Lexapro 444 Somedrug ; data codecntlin; set codes; fmtname ='Code2Drug'; type='C'; start=code; label=name; run; proc format library=work cntlin=codecntlin; run; data example; input code $; name = put(code,$Code2Drug.); datalines; 333 444 ; run;
You can use the formatted values such as
Proc freq data=codes;
tables code;
format code $code2drug.;
run;
Most analysis, reporting and graphic procedures will honor the formats and create groups based on the formatted values if that is of interest.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.