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

Can any one knows how to convert below SAS to Pseudo code ?

 


sum ((case when (mod_r in ('02') and CAL IN ('P') and fec_in <= intnx('month', "PAR_FEC"d, -1, 'end') and EST not in ('7' '07' ' 7' '7 ' '70')
 and temp>0) then temp*SAL_OBL else . end)) as con_temp.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Giving that awful spaghetti code some visual structure (and removing several unnecessary brackets) makes understanding it much easier:

sum (
  case
    when
      mod_r in ('02')
      and CAL IN ('P')
      and fec_in <= intnx('month', "PAR_FEC"d, -1, 'end')
      and EST not in ('7' '07' ' 7' '7 ' '70')
      and temp > 0
    then temp * SAL_OBL
    else . 
  end
) as con_temp

You assign a sum (over several observations, possibly determined by a group by option) to a new variable named con_temp.

This sum is built from the term "temp * SAL_OBL" whenever all the conditions in the when are met.

Hint: this function

intnx('month', "PAR_FEC"d, -1, 'end')

won't work, as the text PAR_FEC is no valid SAS data literal. I suspect this should be a macro variable call &PAR_FEC instead.

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Pseudocode just means sort of code.  There is no defined standard for what that should be.  What you provide there could be pseudocode for how to write an if statement in a datastep for instance.  So no, there is no way to provide something you expect which only you know.

Kurt_Bremser
Super User

Giving that awful spaghetti code some visual structure (and removing several unnecessary brackets) makes understanding it much easier:

sum (
  case
    when
      mod_r in ('02')
      and CAL IN ('P')
      and fec_in <= intnx('month', "PAR_FEC"d, -1, 'end')
      and EST not in ('7' '07' ' 7' '7 ' '70')
      and temp > 0
    then temp * SAL_OBL
    else . 
  end
) as con_temp

You assign a sum (over several observations, possibly determined by a group by option) to a new variable named con_temp.

This sum is built from the term "temp * SAL_OBL" whenever all the conditions in the when are met.

Hint: this function

intnx('month', "PAR_FEC"d, -1, 'end')

won't work, as the text PAR_FEC is no valid SAS data literal. I suspect this should be a macro variable call &PAR_FEC instead.

c4shiva
Calcite | Level 5

Hi 

Thanks a lot for your solution.Smiley Happy

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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