BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi,

I have a data set which should have all of the following in consecutive order:

Q001
Q002
Q003
Q004
'
'
'
Q180

How do I find which ones are missing, for example, if Q 175 is missing?
I tried to do a proc sort, then a proc freq, by this variable, but it's labor intensive to look through each one and determine if one is missing.


Thanks!
4 REPLIES 4
Olivier
Pyrite | Level 9
Hi.
I suggest you sort and deduplicate the values, then compare the number to the previous one in a datastep ; each time the difference is > 1, you print a message.
[pre]
PROC SORT DATA = myData OUT = myValues NODUPKEY ;
BY myVariable ;
RUN ;
DATA _NULL_ ;
SET myValues ;
previousVal = LAG(myVariable) ;
IF _N_>1 THEN DO ;
gap = SUBSTR(myVariable,2) - SUBSTR(previousVal, 2) ;
nbMissing = gap-1 ;
IF nbMissing > 0 THEN PUT nbMissing "missing value(s) between " previousVal " and " myVariable ;
END ;
RUN ;
[/pre]
Regards.
Olivier
deleted_user
Not applicable
This works very well! Thanks so much!
Is it possible to print the list in the output (vs. the log)? Thanks! Message was edited by: jcis
Olivier
Pyrite | Level 9
Of course you can display the list in the Output.
Just add the line :
[pre]
FILE PRINT ;
[/pre]
after the DATA _NULL_ ; statement.

Olivier
deleted_user
Not applicable
Thanks so much! Much appreciated!

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
  • 640 views
  • 0 likes
  • 2 in conversation