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

I haven't ever been a big nested query user, but I'm trying my hand at this one for the sake of brevity in my code. I may have a parenthesis issue, but I've tried a few different ways of adding parenthesis with no luck. Using SAS EG version 7.11.

 

PROC SQL;
CREATE TABLE UNQ_MEMBER AS SELECT 
DISTINCT CIN, INSCODE, REGION, MBR_COUNTY, ENDDTM
FROM (
SELECT 
DISTINCT CIN, INSCODE, REGION, MBR_COUNTY, ENDDTM
FROM MEMBER.MM1718
UNION 
SELECT 
DISTINCT CIN, INSCODE, REGION, MBR_COUNTY, ENDDTM
FROM MEMBER.MM1819
ORDER BY CIN, ENDDTM
) MEMBERSHIP
GROUP BY CIN
HAVING ENDDTM = MAX(ENDDTM);
RUN;

 

The following are my separated queries, where I do get the correct results:

 

/*PULL AND CONCATENATE MEMBERSHIP FOR RELEVANT DATES*/
PROC SQL;
CREATE TABLE MEMBERSHIP AS
SELECT 
DISTINCT CIN, INSCODE, REGION, MBR_COUNTY, ENDDTM
FROM MEMBER.MM1718
UNION 
SELECT 
DISTINCT CIN, INSCODE, REGION, MBR_COUNTY, ENDDTM
FROM MEMBER.MM1819
ORDER BY CIN, ENDDTM;
RUN;


/*GIVES TABLE W/ MOST RECENT DATES*/
PROC SQL;
CREATE TABLE UNQ_MEMBER AS SELECT 
DISTINCT CIN, INSCODE, REGION, MBR_COUNTY, ENDDTM
FROM MEMBERSHIP
GROUP BY CIN
HAVING ENDDTM = MAX(ENDDTM);
RUN;

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

After trimming a few useless bits:

 

PROC SQL;
CREATE TABLE UNQ_MEMBER AS 
SELECT CIN, INSCODE, REGION, MBR_COUNTY, ENDDTM
FROM (
    SELECT 
        CIN, INSCODE, REGION, MBR_COUNTY, ENDDTM
    FROM MEMBER.MM1718
    UNION 
    SELECT 
        CIN, INSCODE, REGION, MBR_COUNTY, ENDDTM
    FROM MEMBER.MM1819 )
GROUP BY CIN
HAVING ENDDTM = MAX(ENDDTM);
QUIT;
PG

View solution in original post

2 REPLIES 2
PGStats
Opal | Level 21

After trimming a few useless bits:

 

PROC SQL;
CREATE TABLE UNQ_MEMBER AS 
SELECT CIN, INSCODE, REGION, MBR_COUNTY, ENDDTM
FROM (
    SELECT 
        CIN, INSCODE, REGION, MBR_COUNTY, ENDDTM
    FROM MEMBER.MM1718
    UNION 
    SELECT 
        CIN, INSCODE, REGION, MBR_COUNTY, ENDDTM
    FROM MEMBER.MM1819 )
GROUP BY CIN
HAVING ENDDTM = MAX(ENDDTM);
QUIT;
PG
Estelle
Calcite | Level 5

Yep that's it thanks

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 3991 views
  • 0 likes
  • 2 in conversation