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;
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)
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)
This worked!
it pulled all that were between those dates in Q2 and Q3
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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.