BookmarkSubscribeRSS Feed
braam
Quartz | Level 8

I'm wondering if there is a way to comment the results of PROC FREQ (or any other PROCs) in a beautiful way. The comment section in the below code is a simple copy&paste from PROC FREQ. Quite often, I make such a comment, so I can keep track of my data and results. Unfortunately, the comment section is messed mostly because of heterogenous indentations. Does anybody have a good suggestion? 

 

 


proc freq data= sashelp.cars;	table make; run;
*
Make Frequency Percent Cumulative
Frequency Cumulative
Percent 
Acura 7 1.64 7 1.64 
Audi 19 4.44 26 6.07 
BMW 20 4.67 46 10.75 
Buick 9 2.10 55 12.85 
Cadillac 8 1.87 63 14.72 
Chevrolet 27 6.31 90 21.03 
Chrysler 15 3.50 105 24.53 
Dodge 13 3.04 118 27.57 
Ford 23 5.37 141 32.94 
GMC 8 1.87 149 34.81 
Honda 17 3.97 166 38.79 
Hummer 1 0.23 167 39.02 
Hyundai 12 2.80 179 41.82 
Infiniti 8 1.87 187 43.69 
Isuzu 2 0.47 189 44.16 
Jaguar 12 2.80 201 46.96 
Jeep 3 0.70 204 47.66 
Kia 11 2.57 215 50.23 
Land Rover 3 0.70 218 50.93 
Lexus 11 2.57 229 53.50 
Lincoln 9 2.10 238 55.61 
MINI 2 0.47 240 56.07 
Mazda 11 2.57 251 58.64 
Mercedes-Benz 26 6.07 277 64.72 
Mercury 9 2.10 286 66.82 
Mitsubishi 13 3.04 299 69.86 
Nissan 17 3.97 316 73.83 
Oldsmobile 3 0.70 319 74.53 
Pontiac 11 2.57 330 77.10 
Porsche 7 1.64 337 78.74 
Saab 7 1.64 344 80.37 
Saturn 8 1.87 352 82.24 
Scion 2 0.47 354 82.71 
Subaru 11 2.57 365 85.28 
Suzuki 8 1.87 373 87.15 
Toyota 28 6.54 401 93.69 
Volkswagen 15 3.50 416 97.20 
Volvo 12 2.80 428 100.00 
;
5 REPLIES 5
Kurt_Bremser
Super User

When I copy/paste the Listing(!) output from EG, I get this:

                        Die Prozedur FREQ

                                           Kumuliert     Kumuliert
Make             Häufigkeit    Prozent     Häufigkeit      Prozent
------------------------------------------------------------------
Acura                    7       1.64             7         1.64  
Audi                    19       4.44            26         6.07  
BMW                     20       4.67            46        10.75  
Buick                    9       2.10            55        12.85  
Cadillac                 8       1.87            63        14.72  
Chevrolet               27       6.31            90        21.03  
Chrysler                15       3.50           105        24.53  
Dodge                   13       3.04           118        27.57  
Ford                    23       5.37           141        32.94  
GMC                      8       1.87           149        34.81  
Honda                   17       3.97           166        38.79  
Hummer                   1       0.23           167        39.02  
Hyundai                 12       2.80           179        41.82  
Infiniti                 8       1.87           187        43.69  
Isuzu                    2       0.47           189        44.16  
Jaguar                  12       2.80           201        46.96  
Jeep                     3       0.70           204        47.66  
Kia                     11       2.57           215        50.23  
Land Rover               3       0.70           218        50.93  
Lexus                   11       2.57           229        53.50  
Lincoln                  9       2.10           238        55.61  
MINI                     2       0.47           240        56.07  
Mazda                   11       2.57           251        58.64  
Mercedes-Benz           26       6.07           277        64.72  
Mercury                  9       2.10           286        66.82  
Mitsubishi              13       3.04           299        69.86  
Nissan                  17       3.97           316        73.83  
Oldsmobile               3       0.70           319        74.53  
Pontiac                 11       2.57           330        77.10  
Porsche                  7       1.64           337        78.74  
Saab                     7       1.64           344        80.37  
Saturn                   8       1.87           352        82.24  
Scion                    2       0.47           354        82.71  
Subaru                  11       2.57           365        85.28  
Suzuki                   8       1.87           373        87.15  
Toyota                  28       6.54           401        93.69  
Volkswagen              15       3.50           416        97.20  
Volvo                   12       2.80           428       100.00  

and it looks the same when I paste it into the code as comment.

braam
Quartz | Level 8
Ah, didn't know that. But I use SAS windows for my job. Just wondering if it's possible here.... not in EG...
Tom
Super User Tom
Super User

Note that the listing output destination has not gone away in SAS, even when you are using Enterprise Guide or SAS/Studio as your programming interface.  It just might take more effort to generate and retrieve the results.

filename results temp;
ods listing file=results  ;
options ls=80 ps=200;
proc freq data= sashelp.cars;	table make ; run;
ods listing close;

data _null_;
  infile results;
  input;
  put _infile_;
run;
SAS 9.4 on WINDOWS                           08:48 Friday, November 22, 2019  75

The FREQ Procedure

                                          Cumulative    Cumulative
Make             Frequency     Percent     Frequency      Percent
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
Acura                   7        1.64             7         1.64
Audi                   19        4.44            26         6.07
BMW                    20        4.67            46        10.75
Buick                   9        2.10            55        12.85
Cadillac                8        1.87            63        14.72
Chevrolet              27        6.31            90        21.03
Chrysler               15        3.50           105        24.53
Dodge                  13        3.04           118        27.57
Ford                   23        5.37           141        32.94
GMC                     8        1.87           149        34.81
Honda                  17        3.97           166        38.79
Hummer                  1        0.23           167        39.02
Hyundai                12        2.80           179        41.82
Infiniti                8        1.87           187        43.69
Isuzu                   2        0.47           189        44.16
Jaguar                 12        2.80           201        46.96
Jeep                    3        0.70           204        47.66
Kia                    11        2.57           215        50.23
Land Rover              3        0.70           218        50.93
Lexus                  11        2.57           229        53.50
Lincoln                 9        2.10           238        55.61
MINI                    2        0.47           240        56.07
Mazda                  11        2.57           251        58.64
Mercedes-Benz          26        6.07           277        64.72
Mercury                 9        2.10           286        66.82
Mitsubishi             13        3.04           299        69.86
Nissan                 17        3.97           316        73.83
Oldsmobile              3        0.70           319        74.53
Pontiac                11        2.57           330        77.10
Porsche                 7        1.64           337        78.74
Saab                    7        1.64           344        80.37
Saturn                  8        1.87           352        82.24
Scion                   2        0.47           354        82.71
Subaru                 11        2.57           365        85.28
Suzuki                  8        1.87           373        87.15
Toyota                 28        6.54           401        93.69
Volkswagen             15        3.50           416        97.20
Volvo                  12        2.80           428       100.00

 

But if you just want data then dumping to the log is the easiest way to do go.  The display might not look exactly the same but is that really the point?

proc freq data= sashelp.cars;	table make /out=counts; run;

data _null_;
  set counts;
  put @1 make @20  count @30 percent;
run;
Acura              7         1.6355140187
Audi               19        4.4392523364
BMW                20        4.6728971963
Buick              9         2.1028037383
Cadillac           8         1.8691588785
Chevrolet          27        6.308411215
Chrysler           15        3.5046728972
Dodge              13        3.0373831776
Ford               23        5.3738317757
GMC                8         1.8691588785
Honda              17        3.9719626168
Hummer             1         0.2336448598
Hyundai            12        2.8037383178
Infiniti           8         1.8691588785
Isuzu              2         0.4672897196
Jaguar             12        2.8037383178
Jeep               3         0.7009345794
Kia                11        2.5700934579
Land Rover         3         0.7009345794
Lexus              11        2.5700934579
Lincoln            9         2.1028037383
MINI               2         0.4672897196
Mazda              11        2.5700934579
Mercedes-Benz      26        6.0747663551
Mercury            9         2.1028037383
Mitsubishi         13        3.0373831776
Nissan             17        3.9719626168
Oldsmobile         3         0.7009345794
Pontiac            11        2.5700934579
Porsche            7         1.6355140187
Saab               7         1.6355140187
Saturn             8         1.8691588785
Scion              2         0.4672897196
Subaru             11        2.5700934579
Suzuki             8         1.8691588785
Toyota             28        6.5420560748
Volkswagen         15        3.5046728972
Volvo              12        2.8037383178

 

braam
Quartz | Level 8
@Kurt_Bremser
@Tom

Thanks for your help. Both look good for me.
My point was: I run many PROCs (FREQ, MEANS, REPORT....) and I want to keep them in my comment section, as a part of SAS code file.

This way I can better understand my code and set next time when I open my code without running my code again. This is actually the function I really like from Jupyter Notebook. So I wanted to mimic this in SAS!


Reeza
Super User
Use a Jupyter Notebook with SAS then....

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
  • 5 replies
  • 568 views
  • 0 likes
  • 4 in conversation