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

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,

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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?

--
Paige Miller

View solution in original post

7 REPLIES 7
Kurt_Bremser
Super User

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;
YangM90
Fluorite | Level 6
Hi Kurt,

thank you!
PaigeMiller
Diamond | Level 26

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?

--
Paige Miller
YangM90
Fluorite | Level 6
Hi Paige!

The data sets are not intergers / row numbers, but arbitrary real numbers.
ed_sas_member
Meteorite | Level 14

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,

YangM90
Fluorite | Level 6
Hi,

thanks alot! 🙂
ed_sas_member
Meteorite | Level 14
You're welcome 🙂
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
  • 7 replies
  • 1718 views
  • 4 likes
  • 4 in conversation