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

Hi, my database need modify existing variables in the Case When syntax for EG.

 

However, I cannot create enough room for condition my new variables:

 

For instance, I can use sas base

data final;
set work.QUERY_FOR_JAN2016_SAS7BDAT1_0003;
if whichone = 'januaryppc' then do;
PRE_MRC = MRC_PRE_JAN;
Post_MRC = MRC_POST_JAN;
pp_from = from_pp_JAN;
pp_to = to_pp_JAN;
changes = changejan;
end;

 

but for EG, I really cannot do that for column changes.

 

Anyway SQL can do multiple column change in a macro statement maybe?

1 ACCEPTED SOLUTION

Accepted Solutions
LinusH
Tourmaline | Level 20

This is a typical case where data step logic is more efficient than SQL, at least from a coding/maintenance point of view.

So if you already have a data step, use that in EG. And then use SQL/Query Builder for other steps.

And you could perhaps use a macro here, but I can't see the benefit. The code/task will be less readable, and harder to maintain.

Data never sleeps

View solution in original post

3 REPLIES 3
Reeza
Super User

In SQL, either query builder or code, you need a case statement for EACH variable change you want to make.

TomKari
Onyx | Level 15

Could you set the month into a macro variable, and then use something like this?

 

...
select
MRC_PRE_&MTH. as PRE_MRC,
MRC_POST_&MTH. as Post_MRC,
from_pp_&MTH. as pp_from,
to_pp_&MTH. as pp_to,
change&MTH. as changes
...

 

Tom

LinusH
Tourmaline | Level 20

This is a typical case where data step logic is more efficient than SQL, at least from a coding/maintenance point of view.

So if you already have a data step, use that in EG. And then use SQL/Query Builder for other steps.

And you could perhaps use a macro here, but I can't see the benefit. The code/task will be less readable, and harder to maintain.

Data never sleeps

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 3 replies
  • 873 views
  • 0 likes
  • 4 in conversation