DATA Step, Macro, Functions and more

read values stord in macro variables into a data set

Accepted Solution Solved
Reply
Super Contributor
Posts: 312
Accepted Solution

read values stord in macro variables into a data set

[ Edited ]

I have 3 data sets, A, B and C and want to compare the total count of them.

I created a number of macro variables by "select into" in proc sql, and want to use these values to make a report.

 

for example, I have three macro variables, count_A, count_B, and count_C, and want to report them in a table like:

type            count

type_A       &count_A

type_B       &count_B

type_C       &count_C

 

I need to read in the values stored in the macro variables. Can they be used in datalines? Thanks.


Accepted Solutions
Solution
‎04-18-2016 03:22 PM
Super User
Posts: 5,093

Re: read values stord in macro variables into a data set

No, not within datalines, but that shouldn't stop you.  A DATA step could proceed:

 

data want;

type='Type A'; count = &count_a; output;

type='Type B'; count = &count_b; output;

type='Type C'; count = &count_c; output;

run;

View solution in original post


All Replies
Solution
‎04-18-2016 03:22 PM
Super User
Posts: 5,093

Re: read values stord in macro variables into a data set

No, not within datalines, but that shouldn't stop you.  A DATA step could proceed:

 

data want;

type='Type A'; count = &count_a; output;

type='Type B'; count = &count_b; output;

type='Type C'; count = &count_c; output;

run;

Super User
Posts: 10,538

Re: read values stord in macro variables into a data set

How many do you have in reality?

Do you want 3 observaions with the values in one variable, one observation with three variables and the values or something else?

 

I'm sure I can force something into datalines but if you do not want all of the values as a single variable in multiple observations it would be a lot of work.

 

I would ask where are these macro variables coming from? It may be easier to address at that point then kluding elsewhere.

 

To create a set with 3 variables:

 

Data want;

   type_A   =  "&count_A";

   type_B   =  "&count_B";

   type_C   =   "&count_C;

   output;

run;

 

Assuming the values are character. Skip the quote marks if the values are always numeric (or . or the special missing tags).

If you want to control the length of the variables for use, such as merging with another set, then add a length statement before the assignment.

  

 

Super Contributor
Posts: 312

Re: read values stord in macro variables into a data set

Thank you very much for both replies. Both works.

 

Respected Advisor
Posts: 4,659

Re: read values stord in macro variables into a data set

No need for macros. Why not use dictionary.tables

 

proc sql;
create table setSizes as
select memname "Type", nobs "Count"
from dictionary.tables
where libname="SASHELP" and memname in ("CLASS","CARS","IRIS");
select * from setSizes;
quit;
PG
Super Contributor
Posts: 312

Re: read values stord in macro variables into a data set

Thank you very much, , for your nice idea and sample code.

I love this community. Everytime I asked a question I learned a lot more than I expected.

 

☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 397 views
  • 3 likes
  • 4 in conversation