David Reese
David Reese

Reputation: 21

Proc format variable format not showing up

I am trying to apply format to a variable in a data set, but after running the data step, I am still only seeing the raw values ( eg -1) instead of formatted values( eg -1=INAPPLICABLE). minimal re-producible code example below. Any help at all greatly appreciated.

  proc format library=PUFLIB;
  '-1' = '-1 INAPPLICABLE'
  '1' = '1 YES'
  '2' = '2 NO'
  '3' = '3 DOES NOT WORK'
    ;
run;
  data example_ds;
   FORMAT ACCDNWRK $ACCDNWRK_FMT.;
input accdnwrk $;
datalines;
1
2
3
-1
;

Upvotes: 2

Views: 1301

Answers (2)

Reeza
Reeza

Reputation: 21294

Please ensure to review your log.

It shows that the error is right after your PROC FORMAT statement. In this case you're missing the code that tells you SAS if the format is a informat or format and the format name.

 70         
 71          proc format library=PUFLIB;
 72           '-1' = '-1 INAPPLICABLE'
              ____
              180
 ERROR 180-322: Statement is not valid or it is used out of proper order.
 73           '1' = '1 YES'
 74           '2' = '2 NO'
 75           '3' = '3 DOES NOT WORK'
 76             ;
 NOTE: The previous statement has been deleted.
 77         run;

 NOTE: PROCEDURE FORMAT used (Total process time):
       real time           0.00 seconds
       cpu time            0.01 seconds

Adding in value to indicate it's a format and then the format name, accwrk_fmt is what's needed.

proc format library=puflib;
value accwrk_fmt
*rest of your code*

Upvotes: 2

PeterClemmensen
PeterClemmensen

Reputation: 4937

You seem to want a numeric format. Hope this helps you

proc format;
   value ACCDNWRK_FMT
      -1 = '-1 INAPPLICABLE'
       1  = '1 YES'
       2  = '2 NO'
       3  = '3 DOES NOT WORK'
;
run;

data example_ds;
FORMAT ACCDNWRK ACCDNWRK_FMT.;
input accdnwrk;
datalines;
1
2
3
-1
;

Upvotes: 1

Related Questions