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

Hello all,

I'm trying to automate my program in which it will select the observation with the highest salary using SYMPUTX and SYMGET and simply replace the macro variable to the correct value.  However, the macro value isn't be replaced, rather going to eof.  Although I do get the 1 correct observation (4     D     $87,545) returned I'm trying to keep all original 5 obs in the data set.  I think I'm butchering the syntax.  Any idea?

Thanks,

David

ID          Name               Salary

1          A                        $20,000

2          B                        $30,475

3          C                        $26,895

4          D                        $87,975

5          E                        $42,545

data salary;

     set Emp_Payroll end=final;

     call symputx('highsal',employee_id,salary);

     call symputx('empid',employee_id);

     if salary>symget('highsal');

     if final then do;

          call symputx('highsal',salary);

     end;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
David_S
Fluorite | Level 6

Thanks for information.  My goal was to try and avoid using the proc sort and have the macro variable overwrite.  So, I guess I'm really trying to compare the previous salary and, if higher, overwrite that value to the salary macro.

I do appreciate your insight.

David

View solution in original post

5 REPLIES 5
dkb
Quartz | Level 8 dkb
Quartz | Level 8

Could you post your log, please?  When I run your code, I get 5 observations on the table and the wrong high value.

Code:

data Emp_Payroll;

input employee_ID Name $ Salary;

datalines;

1          A                        20000

2          B                        30475

3          C                        26895

4          D                        87975

5          E                        42545

;

run;

data salary;

     set Emp_Payroll end=final;

     call symputx('highsal',employee_id,salary);

     call symputx('empid',employee_id);

     if salary>symget('highsal');

     if final then do;

          call symputx('highsal',salary);

     end;

run;

%put &highsal. &empid.;

Log:

25         data salary;

26              set Emp_Payroll end=final;

27              call symputx('highsal',employee_id,salary);

28              call symputx('empid',employee_id);

29              if salary>symget('highsal');

30              if final then do;

31                   call symputx('highsal',salary);

32              end;

33         run;

NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).

      27:41  

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).

      29:16  

NOTE: There were 5 observations read from the data set WORK.EMP_PAYROLL.

NOTE: The data set WORK.SALARY has 5 observations and 3 variables.

NOTE: DATA statement used (Total process time):

      real time           0.09 seconds

      cpu time            0.03 seconds

     

34         %put &highsal. &empid.;

42545 5

Jagadishkatam
Amethyst | Level 16

could you please try the below code. To get the highest salary employee details along with salary we need to sort the data by salary.

data Emp_Payroll;

input ID$           Name$               Salary :dollar8.;

cards;

1          A                        $20,000

2          B                        $30,475

3          C                        $26,895

4          D                        $87,975

5          E                        $42,545

;

proc sort data=Emp_Payroll;

by Salary;

run;

data salary;

     set Emp_Payroll end=final;

     if final then do;

         call symputx("empid",id);

         new=symget("empid");

         call symputx("highsal",salary);

     end;

run;

%put &empid &highsal ;

Thanks,

Jag

Thanks,
Jag
David_S
Fluorite | Level 6

Thanks for information.  My goal was to try and avoid using the proc sort and have the macro variable overwrite.  So, I guess I'm really trying to compare the previous salary and, if higher, overwrite that value to the salary macro.

I do appreciate your insight.

David

Astounding
PROC Star

Well, some of the syntax is clearly not what you actually ran.  The first CALL SYMPUTX uses SALARY as the third argument ... certainly not what you intended.

Why all this macro language?  Why not a simpler version:

data salary;

     set Emp_Payroll end=final;

     retain highsal;

     if salary > highsal then highsal = salary;

     if final then do;

          call symputx('highsal', highsal);

     end;

run;

Also note that it is not clear whether SALARY is numeric or character in your data.  If it is character, $9,000 would be greater than all the salaries you have shown and this would probably be the wrong answer.  Even if you don't have salaries that low, as a character string $100,000 would be smaller than all the salaries you have shown which would again give you the wrong answer.

Good luck.

David_S
Fluorite | Level 6

Correct, not what I actually ran.  I abbreviated to prevent employee information from being compromised thus not an accurate log to provide.  This is certainly more concise but I should have been more clear as to what my intended goal is...to overwrite the higher salary value when comparing the previous iteration.  I'm all ears if you would know how best to compare the first ob to the next and if that salary is higher have it overwrite the macro in SYMPUTX.

Thanks for the help.

David

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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