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

How do I change this conditional statement in to Macro? ( when event_name 1 then pmdWk=24, when event_name 2= then pmdWk=24+24=48, ..........) 

data Smerge;
merge test
           fmerge;
by Id ;
length pmdWk 8.;

pmdWk = scan( PmdVisit, 2, '_');
length event_name 8.;

event_name=scan(RD_event_name, 2,'_');
if event_name= '1' then Npmdwk= pmdWk;
if event_name= '2' then Npmdwk= sum(pmdWk+24);
if event_name= '3' then Npmdwk= sum(pmdWk+48);
if event_name= '4' then Npmdwk= sum(pmdWk+72); and continues...........

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Change what?

How?

What are you trying to do?

Where does macro code come in? Macros write code. So you would start with a complete working data step first.

 

And you show no macro code so haven't got a starting place. Note that the type of DATA manipulation is typically not the place for macros.

 

I might guess if the goal is to add multiples of 24 to a variable:

data Smerge;
   merge test
         fmerge;
   by Id ;
   length pmdWk 8.;

   pmdWk = scan( PmdVisit, 2, '_');
   length event_name 8.;

   event_num=input(scan(RD_event_name, 2,'_'),best.); 
   Npmdwk= sum(pmdWk, (event_num-1)*24 );
run;

Sometimes algebra is your friend.

This might have popped out easier if you think of

if event_name= '1' then Npmdwk= pmdWk;

as

if event_name= '1' then Npmdwk= sum( pmdWk, 0);

 

 

View solution in original post

5 REPLIES 5
hjjijkkl
Pyrite | Level 9
Thank you KurtBremser!
But, How do I incorporate your code with the if/then statement ?
Thank you!
PaigeMiller
Diamond | Level 26

@hjjijkkl wrote:
Thank you KurtBremser!
But, How do I incorporate your code with the if/then statement ?
Thank you!

The code provided does exactly what you want ... try it.

--
Paige Miller
Kurt_Bremser
Super User

@hjjijkkl wrote:
Thank you KurtBremser!
But, How do I incorporate your code with the if/then statement ?
Thank you!

No need for if/then. The code solves this with the formula. Try it (Maxim 4).

ballardw
Super User

Change what?

How?

What are you trying to do?

Where does macro code come in? Macros write code. So you would start with a complete working data step first.

 

And you show no macro code so haven't got a starting place. Note that the type of DATA manipulation is typically not the place for macros.

 

I might guess if the goal is to add multiples of 24 to a variable:

data Smerge;
   merge test
         fmerge;
   by Id ;
   length pmdWk 8.;

   pmdWk = scan( PmdVisit, 2, '_');
   length event_name 8.;

   event_num=input(scan(RD_event_name, 2,'_'),best.); 
   Npmdwk= sum(pmdWk, (event_num-1)*24 );
run;

Sometimes algebra is your friend.

This might have popped out easier if you think of

if event_name= '1' then Npmdwk= pmdWk;

as

if event_name= '1' then Npmdwk= sum( pmdWk, 0);

 

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 730 views
  • 0 likes
  • 4 in conversation