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

@udden2903 wrote:

 

 

Would you mind quickly explaining what your code does? I'm new to macros and I think gaining some understanding of your code would be helpful as I start learning more about them.


 

1 %let locf=patientid diag:;
2 data patients;
3   if 0 then set patients;
4   update patients(obs=0 keep=&locf) patients(keep=&locf);
5   by patientid;
6   set patients(drop=&locf);
7   output;
8   run;
  1. define the list of variables and KEY(S) to be LOCFed so we only have to type it once.
  2. create a new data set (same name as old)
  3. preserve order of variables in the new data set using the old
  4. update patients zeros obs with itself as transaction file (using missingcheck feature of update to LOCF)
  5. update requires a by statement and this resets the LOCF at the start of each PATIENTID.
  6. Bring in the variable we don't want LOCFed.
  7. output needed because UPDATE outputs on LAST.(by-var) by default.
  8. run

There is really no MACRO here just the macro variable (symbolic variable) LOCF

 

udden2903
Obsidian | Level 7

How would you modify this code to make sure that the dummy values from the previous observation continue into the current observation ONLY if the current observation has missing values for ALL of the dummy variables? Right now, the value of a dummy variable is carried forward as long as the value of that variable is missing in the next observation, without any consideration of the values of the other dummy variables.

udden2903
Obsidian | Level 7
I got it to work now! Thanks for your help!
Ksharp
Super User

Be careful. John King's code would work only if year don't have any missing value .

data_null__
Jade | Level 19

@Ksharp wrote:

Be careful. John King's code would work only if year don't have any missing value .


@Ksharpapparently you didn't read the whole thread.  You don't know what you're talking about.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 19 replies
  • 2096 views
  • 3 likes
  • 5 in conversation