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.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.