BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8

   there are these columns in a table: acct_number cust_id and pin.
    there are millions of records.
   but I would like to select only those which have the following combination:

   acct_nbr    cust_id    pin
    1234        111        Abc
    2345        111        pqr


   i.e if a cust_id has different acct_nbr and differt pin.

3 REPLIES 3
stat_sas
Ammonite | Level 13

proc sql;

select * from have

group by cust_id

having count(distinct acct_nbr)>1 and count(distinct pin)>1;

quit;

SASPhile
Quartz | Level 8

Thaks Stat:

  the above table have , I need to join with another table.

  the other table has cust_id and flag. and flag has values like M,L,P and blank

   I would like to get only those values where first record is M and second is a blank.

The output looks like:

acct_nbr    cust_id    pin     flag

    1234        111        Abc    M

    2345        111        pqr

jwillis
Quartz | Level 8

SASPhile,

Take the second table and find all the ID's with flag M and the ID is in Have to create table 'secondM'.  Then go back to the second table and capture all the rows that have an ID in 'secondM' creating table 'secondZ'.  All the ID's in 'secondZ' are matched to your criteria. Then join the Have and Second tables where ID's match and ID's are in 'secondZ'.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 744 views
  • 0 likes
  • 3 in conversation