BookmarkSubscribeRSS Feed
cm3
Fluorite | Level 6 cm3
Fluorite | Level 6

Hi 

 

I’ve data like below

 

accno.  Var1 var2 var3 

111.       Y.     Y.     N

112.       Y.     Y.     Y

113.       N.    Y.      Y

114.       Y.     N      N

115.       Y.     Y.      Y

116.       Y.     Y.     Y

117.       Y.     Y.     N

118.       Y.     Y.     Y

119.       Y.     Y.     Y

120.      N.     Y.     Y

 

i need output as below by considering only Y values for Var1,...

tot.   %var1.   %var2. %var3

10.     80.          90.       70

 

 

please advise. Thank you

 

9 REPLIES 9
novinosrin
Tourmaline | Level 20

Do you want the output as dataset or report?

cm3
Fluorite | Level 6 cm3
Fluorite | Level 6

I’ve input dataset with more than 1000 records

 

can you suggest with both options, if possible 

 

thank you

PGStats
Opal | Level 21

With SQL

 

proc sql;
select 
    count(*) as tot,
    sum(var1="Y")/count(var1) as pctVar1 label="%Var1" format=percent7.0,    
    sum(var2="Y")/count(var2) as pctVar2 label="%Var2" format=percent7.0,    
    sum(var3="Y")/count(var3) as pctVar3 label="%Var3" format=percent7.0
from have;
quit;
PG
cm3
Fluorite | Level 6 cm3
Fluorite | Level 6

Thank you very much

 

Can I use any proc procedure for this ?

PGStats
Opal | Level 21

The procedure is proc SQL. If you want to create a new dataset instead of displaying the results, add

 

create table want as

 

 just before select ...

PG
cm3
Fluorite | Level 6 cm3
Fluorite | Level 6

I need single observation as output, but above proc sql giving output with all my 1000 above observations.....

cm3
Fluorite | Level 6 cm3
Fluorite | Level 6

Can you pls help to get as single observation output, thank you

learsaas
Quartz | Level 8
data  result;
	set a end=last;
	array array_Var Var1-Var3;
	length tot 8;
	array array_Per Per1-Per3;
	if _n_=1 then do over array_Var;
		array_Per=0;
	end;
	do over array_Var;
		if array_Var='Y' then array_Per+1;
	end;
	if last then do;
		tot=_n_;
		do over array_Var;
			array_Per=round(array_Per/tot*100,1);
		end;
		output;
	end;
	keep tot Per1-Per3;
run;
ballardw
Super User

@cm3 wrote:

Hi 

 

I’ve data like below

 

accno.  Var1 var2 var3 

111.       Y.     Y.     N

112.       Y.     Y.     Y

113.       N.    Y.      Y

114.       Y.     N      N

115.       Y.     Y.      Y

116.       Y.     Y.     Y

117.       Y.     Y.     N

118.       Y.     Y.     Y

119.       Y.     Y.     Y

120.      N.     Y.     Y

 

i need output as below by considering only Y values for Var1,...

tot.   %var1.   %var2. %var3

10.     80.          90.       70

 

 

please advise. Thank you

 


Are the values "Y"  or "Y."  That is two different values. Similar with "N." and "N". So do you want percent of "Y" or "Y."?

 

I  you use 1/0 numeric coding instead of Y/N character coding (or read external data of Y/N into 1/0) this becomes a trivial exercise.

The SUM of 1/0 codes values becomes the number of 1 (or Yes or Y or True or what have you responses) and the mean is a percentage.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 1437 views
  • 1 like
  • 5 in conversation