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

I have two datasets.

DATASET2 is a database.

I want to find only the info about missing records from DATASET2(with var1 the DATASET2 might have multiple recorde)

They have var1 in common

How can i use the CNTLIN to acheive this????

Is there any other easier??

DATASET1                             DATASET2
var1    var2                              var1  ....................

101     a

102   b

103    missing

104   missing

105   missing

106   missing

107  f

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

For the sake of demonstration ...

/* Create a CNTLIN dataset as a SAS view with the required variable names */

data missFormat / view=missFormat;
set dataset2;
FMTNAME = "missFormat";
START = var1;
LABEL = strip(var2);
run;

/* Create the format */

proc format cntlin=missFormat; run;

/* Use the format to subset data, for example */

data dataset3;
set dataset1(where=(put(var1,missFormat.)="missing"));
run;

Not that I would ever do this...

PG

PG

View solution in original post

4 REPLIES 4
DBailey
Lapis Lazuli | Level 10

I'm not sure how proc format applies or that I understand your question...but generally you can check for the existence of a record in a different table several ways.  One is:

Proc sql;

create table want as

select

     t1.*

from

     dataset1 t1

     left outer join dataset2 t2

          on t1.var1=t2.var1

where

     t2.var1 is null;

quit;

PGStats
Opal | Level 21

How about:

proc sql;

create table missing as

select * from dataset2

where var1 in (select var1 from dataset1 where upcase(var2)="MISSING");

quit;

PG

PG
robertrao
Quartz | Level 8

Hi ,

It was vwery helpful.Thanks for the replies...Could you also help me with creating CNTLIN...I am in the process of learning

Regards

PGStats
Opal | Level 21

For the sake of demonstration ...

/* Create a CNTLIN dataset as a SAS view with the required variable names */

data missFormat / view=missFormat;
set dataset2;
FMTNAME = "missFormat";
START = var1;
LABEL = strip(var2);
run;

/* Create the format */

proc format cntlin=missFormat; run;

/* Use the format to subset data, for example */

data dataset3;
set dataset1(where=(put(var1,missFormat.)="missing"));
run;

Not that I would ever do this...

PG

PG

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!

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.

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
  • 4 replies
  • 861 views
  • 6 likes
  • 3 in conversation