02-24-2016 09:49 AM
I am trying to put original variable and formatted variable values together. This does not work since I have to format the original value. Is there a way to get around this?
proc format; value type 1="good" 2="bad"; run; data have; input x; cards; 1 2 ; data want; set have; format x type.; y='x'; test1=vvalue(x); test2=vvaluex(y); run;
x test1 test2
1 good good
2 bad bad
02-24-2016 10:04 AM
Make a new copy of the format where the decode includes the codes. So
value type 1="good" 2="bad" ;
Is converted to
value type 1="1 good" 2="2 bad" ;
Personally I have a utility macro that will convert a format catalog. So if I had a catalog name MYLIB.FORMATS I can run the macro and generate a catalog MYLIB.CFORMATS. Then I can just change the FMTSEARCH option. So when I am writing my program and debugging I can use the CFORMATS version and see the code so I know how to write my IF and WHERE statements. Then when I produce the final report I can use the regular format catalog and the numbers do not appear.
02-24-2016 10:11 AM
Yep, another options is to not use formats at all, put code and decode in a dataset. CDISC has this kind of approach as its XML based, and it would be my preferred approach to avoid proprietary file formats, which as shown by the debacle of 32 and 64 bit catalogs goes to show.
02-24-2016 10:38 AM
Here is one example from my side, you could also do merging, i.e. merge on code=x which would be less resource hunry on bigger datasets as in the second example:
data codes; code=1; decode="good"; output; code=2; decode="bad"; output; run; data have; input x; cards; 1 2 ; run; proc sql;
create table WANT as
(select THIS.DECODE from CODES THIS where THIS.CODE=X) as DECODED_VALUE
create table WANT2 as
B.DECODE as DECODED_VALUE
from HAVE A
left join CODES B
Need further help from the community? Please ask a new question.