BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Natural
Fluorite | Level 6

A simple generated format statement is being corrupted so that the results bears little resemblence to the original format.

 

These format statements:

 

13602  proc format LIBRARY=work cntlout=work.library;
13603
13604  %include "L:\er\data\china\tianjin\temp\format3.txt";
NOTE: %INCLUDE (level 1) file L:\er\data\china\tianjin\temp\format3.txt is file L:\er\data\china\tianjin\temp\format3.txt.
13605 +picture QG04fmt
13606 +1 = "Every day "
13607 +2 = "Nearly every day "
13608 +3 = "3 or 4 times a week "
13609 +4 = "Once or twice a week "
13610 +5 = "2 or 3 times a month "
13611 +6 = "About once a month "
13612 +7 = "6-11 times a year "
13613 +8 = "1-5 times a year "
13614 +9 = "No alcohol during the past 12 months "
13615 +99 = "Unknown "
13616 +. = "NA "
13617 +;
NOTE: Format QG04FMT is already on the library WORK.FORMATS.
NOTE: Format QG04FMT has been output.
13618 +picture QG04Afmt
13619 +1 = "Maybe Every day "
13620 +2 = "Nearly every day "
13621 +3 = "About 3 or 4 times a week "
13622 +4 = "Once or twice a week "
13623 +5 = "like 2 or 3 times a month "
13624 +6 = "About once a month "
13625 +7 = "a6-11 times a year "
13626 +8 = "1-5 times a year "
13627 +9 = "No alcohol during the past 12 months"
13628 +99 = "Unknown "
13629 +. = "NA, this is just sillines. "
13630 +;
NOTE: Format QG04AFMT is already on the library WORK.FORMATS.
NOTE: Format QG04AFMT has been output.
NOTE: %INCLUDE (level 1) ending.
13631  format qf01 qf05a qf06a ddmmyys10.;
13632  format qf02 qf05b qf066 qf06b hhmm.;
13633  run;

 

and

 

13665  data china.erfinalf912a;
13666  %include  "L:\er\data\china\tianjin\temp\formats.txt";
NOTE: %INCLUDE (level 1) file L:\er\data\china\tianjin\temp\formats.txt is file L:\er\data\china\tianjin\temp\formats.txt.
13667 +format
13668 +
13669 +QG04 QG04fmt.
13670 +QG04A QG04Afmt.
13671 +;
NOTE: %INCLUDE (level 1) ending.
13672  set china.erfinalnf912;
13673  run;

 

produce:

 

                                                        The SAS System                     12:29 Tuesday, September 12, 2017  49

                                                        The FREQ Procedure

                         PAST YEAR, HOW OFTEN DO YOU DRINK THE EQUIVALENT OF 5-11 DRINKS ON ONE OCCASION?

                                                                                      Cumulative    Cumulative
                                                     QG04    Frequency     Percent     Frequency      Percent
                    ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
                                                      NA          117       22.37           117        22.37
                                               Every day           23        4.40           140        26.77
                                        Nearly every day           29        5.54           169        32.31
                                     0 or 3 times a week           22        4.21           191        36.52
                                    Once or twice a week            6        1.15           197        37.67
                                    0 or 5 times a month           33        6.31           230        43.98
                                      About once a month           15        2.87           245        46.85
                                       0-07 times a year           36        6.88           281        53.73
                                        0-8 times a year           85       16.25           366        69.98
                                               09 months          154       29.45           520        99.43
                                                 Unknown            3        0.57           523       100.00


                         PAST YEAR, HOW OFTEN DO YOU DRINK THE EQUIVALENT OF 1-4 DRINKS ON ONE OCCASION?

                                                                                     Cumulative    Cumulative
                                                   QG04A    Frequency     Percent     Frequency      Percent
                    ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
                             NA, this is just sillines.          117       22.37           117        22.37
                                        Maybe Every day           54       10.33           171        32.70
                                       Nearly every day           87       16.63           258        49.33
                                    0 or 3 times a week           39        7.46           297        56.79
                                   Once or twice a week           34        6.50           331        63.29
                                   0 or 5 times a month           69       13.19           400        76.48
                                     About once a month           12        2.29           412        78.78
                                      0-07 times a year           10        1.91           422        80.69
                                       0-8 times a year           92       17.59           514        98.28
                                               09 months           1        0.19           515        98.47
                                                Unknown            8        1.53           523       100.00

 

Why are the formats being corrupted?

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Natural
Fluorite | Level 6

The solution was to replace the "picture" statement with a "value" statement.  And that did it!

 

thanksK

View solution in original post

6 REPLIES 6
RW9
Diamond | Level 26 RW9
Diamond | Level 26

What do you mean?  You have created some formats, and applied them, what corruption are you talking about?  Note you supply some freq output, but there is no code for that?

Natural
Fluorite | Level 6

I mean the format statement looks like:

picture QG04fmt
1 = "Every day "
2 = "Nearly every day "
3 = "3 or 4 times a week "
4 = "Once or twice a week "
5 = "2 or 3 times a month "
6 = "About once a month "
7 = "6-11 times a year "
8 = "1-5 times a year "
9 = "No alcohol during the past 12 months "
99 = "Unknown "
. = "NA "
;

but the results is:

 

                                                     QG04    Frequency     Percent     Frequency      Percent
                    ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
                                                      NA          117       22.37           117        22.37
                                               Every day           23        4.40           140        26.77
                                        Nearly every day           29        5.54           169        32.31
                                     0 or 3 times a week           22        4.21           191        36.52
                                    Once or twice a week            6        1.15           197        37.67
                                    0 or 5 times a month           33        6.31           230        43.98
                                      About once a month           15        2.87           245        46.85
                                       0-07 times a year           36        6.88           281        53.73
                                        0-8 times a year           85       16.25           366        69.98
                                               09 months          154       29.45           520        99.43
                                                 Unknown            3        0.57           523       100.00

 

Where did the "0" come from in the 4th line?  The value 9 should be formatted at "No alcohol during the past 12 months "

not "09 months".  What's going on?

 

thanks in advance!

Roger

 

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, first off why are you using the term picture, its a one to one mapping no picture going on.  That could well be why things are acting up, use;

proc format;

  value QG04fmt
    1="Every day "
    2="Nearly every day "

...;

run;

Natural
Fluorite | Level 6

The solution was to replace the "picture" statement with a "value" statement.  And that did it!

 

thanksK

RW9
Diamond | Level 26 RW9
Diamond | Level 26

For future reference, please mark the post which answered the question as the Correct response.  

Tom
Super User Tom
Super User

It is replacing the digits in the display value with the digits in the actual value.  If you don't want the format to do that then don't define the format as a PICTURE format. Just use the VALUE keyword so that you define a normal format.

 

Try this little program.

proc format ;

picture QG04fmt
1 = "Every day "
2 = "Nearly every day "
3 - 98 = "3 or 4 times a week "
99 = "Unknown "
. = "NA "
;
run;
data _null_;
  do x=1,2,3,4,5,11,12,98,99,. ;
    y=put(x,qg04fmt.);
    put x= y= ;
  end;
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1325 views
  • 0 likes
  • 3 in conversation