DATA Step, Macro, Functions and more

Assign Output To Variable

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

Assign Output To Variable

How do i assign the SINGLE output of an step to a variable inside a macro?

 

E.G: There is only one distinct value of a character variable in a dataset. I want to assign that Distinct Value to 't';

Please Help, How Can We Do It?

 

It's like i want:

%Let t = %Eval(Proc Sql; Select Distinct(XYZ) From Prq; QuitSmiley Wink


Accepted Solutions
Solution
‎01-20-2016 05:57 PM
Super User
Posts: 9,681

Re: Assign Output To Variable

proc sql;
Select Distinct(XYZ) into : T
 From Prq;
Quit;

%put &T ;

View solution in original post


All Replies
Solution
‎01-20-2016 05:57 PM
Super User
Posts: 9,681

Re: Assign Output To Variable

proc sql;
Select Distinct(XYZ) into : T
 From Prq;
Quit;

%put &T ;
Super User
Posts: 5,083

Re: Assign Output To Variable

SQL will do that for you.  Include a separator, just in case there is more than one possible value for XYZ:

 

proc sql;

select distinct xyz into : t separated by ' ' from Prq;

quit;

 

 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 195 views
  • 2 likes
  • 3 in conversation