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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 343 views
  • 0 likes
  • 3 in conversation