BookmarkSubscribeRSS Feed
Rebecca7
Calcite | Level 5

Good day All,

I am new on SAS  community, I am preparing for base certification exam and I came across this code that I am expected to fix and run. 

I used the example someone posted but each time i run my code it writes notes in the log but after sorting the data, I am not able to do a proc print, to enable me visualize the output so i can answer the questions that follow, rather when I run the code it loops forever and does not give me any result. This is the code:

 

 data work.lowchol work.highchol;

 set sashelp.heart;

     if cholesterol lt 200 output work.lowchol;

     if cholesterol ge 200 output work.highchol;

     if cholesterol is missing output work.misschol;

run;

Thank You.

 

 

2 REPLIES 2
mkeintz
PROC Star

Run the code you posted, and examine the sas log.  That should help you understand what is needed for a "fix".

 

Your approach of running a PROC SORT and PROC PRINT assumes that the preceding data step produced the data you wish to view.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Reeza
Super User

When you run the code posted you should get a bunch of errors. Here's the log I receive. 

You then need to fix the errors in the order they appear.

 

69          data work.lowchol work.highchol;
 70         
 71          set sashelp.heart;
 72         
 73              if cholesterol lt 200 output work.lowchol;
                                       ______
                                       79
 ERROR 79-322: Expecting a ;.
 
 74         
 75              if cholesterol ge 200 output work.highchol;
                                       ______
                                       79
 ERROR 79-322: Expecting a ;.
 
 76         
 77              if cholesterol is missing output work.misschol;
                                __
                                388
                                76
 ERROR 388-185: Expecting an arithmetic operator.
 
 ERROR 76-322: Syntax error, statement will be ignored.
 
 78         
 79         run;
 
 NOTE: The SAS System stopped processing this step because of errors.
 WARNING: The data set WORK.LOWCHOL may be incomplete.  When this step was stopped there were 0 observations and 17 variables.
 WARNING: The data set WORK.HIGHCHOL may be incomplete.  When this step was stopped there were 0 observations and 17 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       user cpu time       0.00 seconds
       system cpu time     0.01 seconds
       memory              1622.84k
       OS Memory           20652.00k
       Timestamp           06/06/2023 04:34:21 PM
       Step Count                        24  Switch Count  4
       Page Faults                       0
       Page Reclaims                     389
       Page Swaps                        0
       Voluntary Context Switches        18
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           528
       
 

 

There are at least 5 mistakes in the code above, three are the 'same'. 

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

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
  • 2 replies
  • 436 views
  • 0 likes
  • 3 in conversation