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

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1185 views
  • 0 likes
  • 2 in conversation