Learning SAS? Welcome to the exclusive online community for all SAS learners.

Could you please help me understand this SAS program code?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

Could you please help me understand this SAS program code?

I am currently working on a sas program file, with of aim of understanding and then updating the analysis performed by somebody else already. In doing so, I need to understand what each and every single sas code does.

However, due to being to new to sas, I am finding it a little hard to understand what has been done in the following sas commands.

CAN ANYBODY PLEASE INTERPRET THESE CODES (GIVEN IN RED) FOR ME? WHAT IS THIS PUT COMMAND DOING?

I will be great full to you for any help in this regard.i

** calculate wage effect ;

  if sex=1 then do ;

     emp_pre_wage  = put(emp_pre ,B07_Q2BAm.)+0 ;

     emp_post_wage = put(emp_post,B07_Q2BAm.)+0 ;

  end ;

  if sex=2 then do ;

     emp_pre_wage  = put(emp_pre ,B07_Q2BAf.)+0 ;

     emp_post_wage = put(emp_post,B07_Q2BAf.)+0 ;

  end ;   

    

  /*

  emp_pre_wage  = put(emp_pre ,B07_Q2BAc.)+0 ;

  emp_post_wage = put(emp_post,B07_Q2BAc.)+0 ;

  */

  if nmiss(emp_pre_wage,emp_post_wage)=0 then

         wage_pw = max(emp_pre_wage - emp_post_wage,0) ;


Accepted Solutions
Solution
‎08-05-2015 02:34 AM
Super User
Posts: 7,766

Re: Could you please help me understand this SAS program code?

Posted in reply to healtheconomist

emp_pre and emp_post seem to be numerical values that are somehow converted with a user-defined format to a character string. The +0 after seems to be there to force a conversion back to numeric (the put function always yields a character type). Bad programming style, IMO.

The final step makes a calculation only when the previous actions left no missing values in emp_pre_wage and emp_post_wage.

In order to understand what happens here, you must find the place where the formats B07_Q2BAm and B07_Q2BAf are defined.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Solution
‎08-05-2015 02:34 AM
Super User
Posts: 7,766

Re: Could you please help me understand this SAS program code?

Posted in reply to healtheconomist

emp_pre and emp_post seem to be numerical values that are somehow converted with a user-defined format to a character string. The +0 after seems to be there to force a conversion back to numeric (the put function always yields a character type). Bad programming style, IMO.

The final step makes a calculation only when the previous actions left no missing values in emp_pre_wage and emp_post_wage.

In order to understand what happens here, you must find the place where the formats B07_Q2BAm and B07_Q2BAf are defined.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 9

Re: Could you please help me understand this SAS program code?

Posted in reply to KurtBremser

Dear KutBemser,

Thanks very much for your kind and helpful answer to my message. Yes, emp_pre (employment category pre-disease) and emp_post (employment category post-disease) are the numerical values (range from 1 to 20, depending on the kind of occupation category pre and post scenario). as per information provided in the report, it suggests that occupation and gender specific average income has been attributed to each occupation category with a view to calculate the cost from lost wages as a result of disease (MS). B07_Q2BAm and B07_Q2BAf seem to be the profession and gender specific income categories..

Let me dig further into this, by contacting the author and requesting him to provide me with the background material (used in creation of the formats you noted) and I will share with you.


But story is pretty much clear now. Would be really great if you could please add your further thoughts on this.


Thank you again.

Occasional Contributor
Posts: 9

Re: Could you please help me understand this SAS program code?

Posted in reply to healtheconomist

Dear KurtBremser,

I have found that B07_Q2BAm and B07_Q2BAf are the formats that convert an occupation code to average income of that occupation ( B07_Q2BAm is for male participants and B07_Q2BAf is for females)

But I am still not able to understand what the second last command (copied below for your convenience) is doing?

/*

  emp_pre_wage  = put(emp_pre ,B07_Q2BAc.)+0 ;

  emp_post_wage = put(emp_post,B07_Q2BAc.)+0 ;

  */


is it a sas code? or what?


Thank you in advance for your help

Super User
Posts: 7,766

Re: Could you please help me understand this SAS program code?

Posted in reply to healtheconomist

Anything between /* and */ is a comment and will not have any effect when the program is run.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 9

Re: Could you please help me understand this SAS program code?

Posted in reply to KurtBremser

Thanks very much

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 555 views
  • 4 likes
  • 2 in conversation