BookmarkSubscribeRSS Feed
Patrick
Opal | Level 21
Hi Thomas
Could it be that you're just after that?

%MACRO start(Zahl);
proc sql;
select ID, VERSION into :ID, :VERSION
from myLib.mytable
where LOOK_HERE = &Zahl. AND LOOK_THERE = 'T';
quit;

data test_port;
test_601_ID = &ID.;
test_601_VERSION = &VERSION.;
run;

proc print data = test_port;
run;

%MEND start;

%start(601)


BUT - Then one would may be write it this way:

%MACRO start(Zahl);
proc sql;
select ID as test_&Zahl._ID, VERSION as test_&Zahl._Version
from myLib.mytable
where LOOK_HERE = &Zahl. AND LOOK_THERE = 'T';
quit;
%MEND start;

%start(601)


HTH
Patrick
ThomasH
Calcite | Level 5
Hi,

thanks for your replies - I have changed the code to run the SQL first, which did the job.

However, this works only in case the values I am looking up with the SQL are fixed.

How would that work in case I have an undefined set of variables to look up?

E.g. (pseudo code)

macro test(value)
proc sql;
select x into :var_x from y where z = value;
quit;
mend test;

data someData;
set anotherDataset;
for each row
get the value of column3 and call the proc sql step with the value of column3;
end;
another_column = &var_x;
run;

Hope that gives a picture of what I was thinking about.

Thanks and cheers,
Thomas


Message was edited by: ThomasH Message was edited by: ThomasH
LinusH
Tourmaline | Level 20
Why don't you just join the two tables:

proc sql;

create table SomeData as
select x as another_column
from anotherDataset left join y
on anotherDataset.column3 eq y.z

quit;

Linus
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!

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
  • 17 replies
  • 1236 views
  • 0 likes
  • 11 in conversation