BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8
In the example below the physician has three records.I would like to populate the zip which has max mg for the same physician.So in this case, zip 00972 has the max mg.

physician mg zip
Peter 100 00972
peter 50 00976
peter 25 (blank)

The output :
physician mg zip
Peter 100 00972
peter 50 00972
peter 25 00972

So that I ca roll up at physician and zip level for the total mg.

I tried using this(after sorting):

data temp;
set master_cvv;
by correct_name city state zip;
if first.correct_name then x= zip;
else y = lag(X);
if x= '' then x= y;
zip1 = x;
run;

the final output looks like:

physician mg zip
Peter 100 00972
peter 50
peter 25

Two records,zip appears blank.
Any help in on this?
2 REPLIES 2
Cynthia_sas
SAS Super FREQ
Hi:
The correct method of using LAG is to call it on every row and then adjust the returned value according to your condition. As it explains in the comment to the program in this note:
http://support.sas.com/kb/24/665.html


/* This example shows the difference in output when you use conditional */
/* and unconditional logic in your program. Because the LAG function stores */
/* values on the queue only when it is called, you must call LAG unconditionally */
/* (outside the IF condition) to get the correct answers. (SAS Language Reference, */
/* Dictionary --> Functions and CALL Routines --> LAG function, Example 2) */


Here are some other notes about using LAG:
http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a000212547.htm
http://support.sas.com/kb/24/694.html

If you continue to have difficulty with using the LAG function, you may wish to work with Tech Support on this problem.

cynthia
SASPhile
Quartz | Level 8
Thank you !

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