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.
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;
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;
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.
Thank you very much for both replies. Both works.
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;
Thank you very much, PGStats, for your nice idea and sample code.
I love this community. Everytime I asked a question I learned a lot more than I expected.
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.
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.