BookmarkSubscribeRSS Feed
jessho
Calcite | Level 5

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 

3 REPLIES 3
tsap
Pyrite | Level 9

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.

ballardw
Super User

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.

Reeza
Super User
If it's filling in missing it doesnt' really matter if it's manual or a code fix, either way it's a manual fix. You can fix it manually in SAS or Excel, I don't think there's much of a difference based on what you're saying. One good thing about a code difference is you can document your changes but can also do that in Excel if you add start/end dates to your tables.

*fix Dec 2018;
if rx_code_1 = '9347410' then erxname1 = 'Drug Name';
*fix January 2018;
else if rx_code='4' then erxname1 = 'New Name';

Or find a better data source for DINs to names. There's a few fairly decent databases out there and you likely have it in a system somewhere if it's being used in the facility.

SAS Innovate 2025: Register Now

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!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 3 replies
  • 795 views
  • 1 like
  • 4 in conversation