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)

This worked! 

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.

it pulled all that were between those dates in Q2 and Q3

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.
Thank you!!!!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

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