Hi ,
I have a numeric format for numeric variable;
but I am applying the same format on a charcecter variable (CODE)in the datastep.
could you help me figure out where I went wrong??
Thanks
proc format;
value MSDRG
001-017, 020-042, 113-117, 129-139,="1"
other="0";
run;
data elective_surgical;
set final_with_MSDRG;
where put(Code, MSDRG.)="1";
run;
That depends, what's not working?
The following works for me. I'm confused by your format though, 001-017 is the same as 1-17, if you have leading 0's you likely have a character variable not a numeric variable.
data have;
do code=1 to 200;
output;
end;
run;
proc format;
value MSDRG
001-017, 020-042, 113-117, 129-139="1"
other="0";
run;
data elective_surgical;
set have;
where put(Code, MSDRG.)="1";
run;
You should have a separate charater value format where the value statement is Value $msdrg and use Put(code,$msdrg).
Character and numeric formats are different for a number of reasons.
If Code is character type, then you need transform it into numeric type ,since your format is numeric type.
data have; do i=1 to 200; code=put(i,best8. -l);output; end; drop i; run; proc format; value MSDRG 001-017, 020-042, 113-117, 129-139="1" other="0"; run; data elective_surgical; set have; where put(input(Code,best8.), MSDRG.)="1"; run;
Xia Keshan
Apart from a redundant comma in your proc format your code works fine for me.
If you want to see the leading zeros in your initial numeric values, simply use the z3. format as below.
PROC FORMAT;
VALUE MSDRG
001-017, 020-042, 113-117, 129-139="1"
OTHER="0";
RUN;
DATA FINAL_WITH_MSDRG;
FORMAT CODE Z3.;
CODE = 001;
OUTPUT;
CODE = 140;
OUTPUT;
RUN;
DATA ELECTIVE_SURGICAL;
SET FINAL_WITH_MSDRG;
WHERE PUT(CODE, MSDRG.)="1";
RUN;
If you want to format a character variable to return another character value you can use the PUTC function.
PROC FORMAT;
VALUE $MSDRG
"001"-"017"="1"
OTHER="0";
RUN;
DATA FINAL_WITH_MSDRG;
FORMAT CODE;
CODE = "001";
OUTPUT;
CODE = "140";
OUTPUT;
RUN;
DATA ELECTIVE_SURGICAL;
SET FINAL_WITH_MSDRG;
ATTRIB STUFF FORMAT=$1.;
STUFF=PUTC(CODE, "$MSDRG.")="1";
RUN;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.