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

how would i do a where statement for an alphanumeric variable such as 2021Q2?  I just want to bring in data for 2021 Q2 and Q3:


proc sql;
create table Q2Q3risk as
select
year_qtr,
count(distinct memberNo) as member_dist,
sum(riskTotal) as TotalRisk_Sum,
sum(riskScore) as riskScore_Sum,
sum(riskValueClosed) as riskValueClosed_Sum
from riskpull
where year_qtr in ('2021Q2','2021Q3')
group by year_qtr;
quit;

 

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

Is year_qtr defined as character or numeric with a date format in your dataset? If it is character when your query should work OK. If it is numeric then try this using date constants:

where year_qtr in ('01Apr2021'd,'01Jul2021'd)

View solution in original post

7 REPLIES 7
SASKiwi
PROC Star

Is year_qtr defined as character or numeric with a date format in your dataset? If it is character when your query should work OK. If it is numeric then try this using date constants:

where year_qtr in ('01Apr2021'd,'01Jul2021'd)
Reeza
Super User
Did you confirm this pulls all dates you need and not just those two dates? From your prior descriptions of your data this would not work correctly.
You won't get errors but you won't get the right answers.
Kurt_Bremser
Super User

Maxim3: Know Your Data.

First, verify type and display format of year_qtr, and then, if it is numeric with a YYQ format, the actual raw values, as the dates might be any date within a quarter, so you must convert them to a new value first before you can use them for grouping in SQL.

Reeza
Super User
Don't.
Use your original variable and your original method of filtering the data.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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