If I have two data sets, lets say:
data A;
input ColA;
datalines;
1
2
3
;
run;
data B;
input ColB;
datalines;
1
2
;
run;
Then data set A has 3 rows, while data set B has 2 rows.
I want to create a new data set, containing one element, which is x = the number of rows of A / the number of rows of B.
How can I do that? 🙂
Best regards,
Hello, @YangM90 , I am curious if this is a reasonable example. Are the data sets A and B simply integers that correspond to the row number (value of ColA is 1 in the first row and 2 in the second row and so on)? This seems unrealistic, and could perhaps result in unrealistic answers. Could you please clarify?
See this example:
data a;
set sashelp.class (obs=3);
run;
data b;
set sashelp.class;
run;
data want;
if nobsb ne 0 then x = nobsa / nobsb;
output;
stop;
set a nobs=nobsa;
set b nobs=nobsb;
run;
Hello, @YangM90 , I am curious if this is a reasonable example. Are the data sets A and B simply integers that correspond to the row number (value of ColA is 1 in the first row and 2 in the second row and so on)? This seems unrealistic, and could perhaps result in unrealistic answers. Could you please clarify?
Hi @YangM90
Here is an approach using PROC SQL and the dictionary tables, which contains metadata about SAS datasets.
proc sql;
select case when b.nobs ne 0 then a.nobs / b.nobs else . end as ratio format=8.2
from
(select nobs
from dictionary.tables
where libname="WORK" and upcase(memname) = "A") as a,
(select nobs
from dictionary.tables
where libname="WORK" and upcase(memname) = "B") as b;
run;
Best,
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.