BookmarkSubscribeRSS Feed
sas_Forum
Calcite | Level 5

Hi

I am having a table with column name Empname i want to pick all the empname and create a macr

i tryed by

proc sql;
select empname from emp into:names separted by ',' ;
quit;

i having the Table all_emp i wnat to picek the employes of emp table in all_emp;

2 REPLIES 2
Reeza
Super User

You have no FROM clause telling SAS where to select the data from, as well as separated is spelled incorrectly.

proc sql;

select empname from emp into :names separated by ','

FROM table_name;

quit;

Astounding
PROC Star

Well, you do have a FROM clause, but it is in the wrong place.  Technically, it would be moved:

select empname into : names separated by ',' from emp;

But take a step back for a moment.  Even if you created such a macro variable it wouldn't be useful later.  You would get a list like:

Amy,Peter,Fred

What you really would need in order to utilize a macro variable later is a value like:

"Amy", "Peter", "Fred"

You could get SQL to produce that instead.  But take another step back and you'll see that macro language is the wrong approach for this task.  SQL lets you select matching records.  My SQL might not be good enough, but there are enough SQL programmers on the board to correct this if necessary:

proc sql;

select * from all_emp where name in (select name from emp);

quit;

Good luck.

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
  • 708 views
  • 0 likes
  • 3 in conversation