BookmarkSubscribeRSS Feed
Phil_NZ
Barite | Level 11

Hi SAS Users.

 

I have a code below to create the table work.industry_mtbv

proc sql;
create table work.industry_mtbv as
  select year, INDC3, 
		median(wMAR_TO_BOO) as median_mtbv
  from canus
  group by INDC3,year
  ;
quit;

This means that median_mtbv will be calculated for each INDC3( industry) each year.

I want to add one more condition that: if  INDC3 in ('NA', 'UNCLS', 'UQESQ') then median_mtbv=.  (setting missing for median_mtbv if INDC3 is one of these three industries)

 

Can you please suggest to me how can I adjust the proc SQL above to add this condition?

 

Warmest regards. 

Thank you for your help, have a fabulous and productive day! I am a novice today, but someday when I accumulate enough knowledge, I can help others in my capacity.
1 REPLY 1
andreas_lds
Jade | Level 19

Maybe the CASE-statement could be used, but imho this makes sql even less readable.

I would not use sql for anything, that could be solved by using a normal proc, so:

proc summary data=canus nway;
  class indc3 year;
  var wMAR_TO_BOO;
  output out=work.industry_mtbv(drop= _type_ _freq_) median=median_mtbv;
run;

data work.industry_mtbv;
  set work.industry_mtbv;

  if indc3 in ('NA', 'UNCLS', 'UQESQ') then median_mtbv = .;
run;

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 1 reply
  • 390 views
  • 1 like
  • 2 in conversation