BookmarkSubscribeRSS Feed
GN0001
Barite | Level 11

Hello team,

How to point to another variable in a case statement in a proc sql?

I need to have some calculation after then instead of literal. Instead of something, I need to multiply the value of a variable in the table * by the value of another variable in the table. After then, it is a calculation of two values from two variables from same dataset.

Proc sql;
   create table junk as
   select *,
      case 
         when sex= 'F' then 'something'
         when sex= 'M' then 'something else'
         else 'Error'
      end as newvar label='This is a Sex based value'
   from sashelp.class
   ;
run;

Respectfully,

Blue blue

 

Blue Blue
2 REPLIES 2
Sajid01
Meteorite | Level 14

Can you elaborate please. Your question is not comprehensible.
Do refer to SAS documentation on Proc SQL some of your questions may be answered there.

Tom
Super User Tom
Super User

If you provide a more detailed example of what you are trying to do then you can get a better answer.

 

It sounds like you want something like this:

proc sql;
create table junk as
  select *
       , case 
           when sex= 'F' then weight*height
           when sex= 'M' then age
           else .
         end as newvar label='This is a Sex based value'
  from sashelp.class
;
quit;

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 2 replies
  • 1286 views
  • 1 like
  • 3 in conversation