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

Hi all,

I need to write sql code in sas,

 

variable A divide to Variable b  * 100, if answer more then 5 then give me new variable filled "Y"

using data name Example

Thanks

Thanks,
Vahe
1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

@Rhys solution:

select case when (var_a / var_b)*100 > 5 then 'Y' else 'N' end as var_c

means that result (either Y or N) wil be in var_c variable.

 

View solution in original post

4 REPLIES 4
Rhys
Obsidian | Level 7
select case when (var_a / var_b)*100 > 5 then 'Y' else 'N' end as var_c
from table
Vahe_Mar
Obsidian | Level 7

Then "Y" can you tell me where is my variable which should be equal to "y"

Thanks,
Vahe
Shmuel
Garnet | Level 18

@Rhys solution:

select case when (var_a / var_b)*100 > 5 then 'Y' else 'N' end as var_c

means that result (either Y or N) wil be in var_c variable.

 

ballardw
Super User

As a general note you might want to consider using numeric values of 1 and 0 instead of character 'Y' and 'N'.

If 1 is the value for 'Y' or 'Yes' or however you think then:

 

If varname then <other code> ; treats a value for the variable varname as true.

You can a have a number of different formats to assign a display value of 'Y', 'Yes' ,'True', 'In Compliance' or what have you.

For summary tables such as in proc report or proc tabulate then the N statistics gives how many results are assigned either value, Sum shows number of 'Y' values and mean is percentage of 'Y' values.

If you have multiple variables code this way then Sum of the variables gives a count of how many variables have 'Y' values.

And other coding behaviors are possible that get more cumbersome for character values.

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
  • 4 replies
  • 1339 views
  • 2 likes
  • 4 in conversation