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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

5 REPLIES 5
Astounding
PROC Star

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;

ballardw
Super User

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.

  

 

fengyuwuzu
Pyrite | Level 9

Thank you very much for both replies. Both works.

 

PGStats
Opal | Level 21

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
fengyuwuzu
Pyrite | Level 9

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.

 

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
  • 5 replies
  • 2073 views
  • 3 likes
  • 4 in conversation