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

Hi All,

I have a dataset named " masterdataset" looks like below 

type

Count

A

223

B

123

C

343

D

767

E

233

 

I want to convert every individual rows in to individual macros. Eg: if i will do %put &=A then the result should be 223.

Tried to do with proc sql , but getting error

proc sql;
select distinct typeinto :groupA_bign-:groupB_bign from masterdataset;
quit;

ERROR: The following columns were not found in the contributing tables: masterdataset.

 

Kindly let me know if there is any other way to do this or how to modify the code to get the result.

1 ACCEPTED SOLUTION
3 REPLIES 3
sahoositaram555
Pyrite | Level 9
Thanks,
It worked. @Kurt_Bremser Any comment/valuable inputs on proc sql statement which i have provided?
Kurt_Bremser
Super User

@sahoositaram555 wrote:
Thanks,
It worked. @Kurt_Bremser Any comment/valuable inputs on proc sql statement which i have provided?

SQL does not support the dynamic creation of macro variable names from dataset columns, so it would be extremely clumsy to somehow re-engineer the call symput(x) function with it:

  • determine the number of observations
  • in a macro do loop:
  • get the name from a certain observation (using firstobs= and obs= dataset options)
  • set the value in a similar way, using the name from the previous step

This algorithm is just a suggestion, not tested in any way. I'm not sure if the obs= and firstobs= dataset options work in proc sql.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1483 views
  • 0 likes
  • 2 in conversation