—•Today is •—

Another method of removing invalid characters or identifying false values is by using the COMPRESS function. In this example, we will assume that the valid characters for the Member ID are numbers 0 to 9 and letters A to Z. The first step will compress out all of the valid characters and create a variable which contains the invalid characters. Then the second step is to rerun the COMPRESS function to compress out all of the invalid characters that were found.


	//USR0C2CJ  JOB (1234),'MaQI-CMC-x6354',
	//          TIME=1440,MSGLEVEL=(1,1),MSGCLASS=X,REGION=4096K,
	//          CLASS=M,USER=USR0C2C,NOTIFY=USR0C2C
	//STEP1     EXEC PGM=IEFBR14
	//SASMULTI  DD DISP=(NEW,PASS),UNIT=SYSDA,
	//          SPACE=(CYL,(2000,0)),VOL=(,,,3)
	//STEP2     EXEC SAS8
	//WORK      DD DISP=(OLD,DELETE,DELETE),DSN=*.STEP1.SASMULTI
	//SASUSER   DD DISP=SHR,DSN=USR0C2C.SAS8.SASUSER
	//SYSIN     DD *
	options errors=5 missing=0 errorabend mlogic source2 symbolgen nodate
          cmpopt sortname=sort;

	libname lab 'tests.rst.cmc.montelab.data' disp=shr;

	data montelab;
  	set lab.montelab;
     	/* identify invalid characters */
  	unwanted=compress(upcase(memberid),
  	  '1234567890ABCDEFGHIJKLMNOPQRTSUVWXYZ');
     	/* remove invalid characters */
  	memberid2=compress(memberid,unwanted);
	run;
				

	SAS Output
	
	Obs    MemberID     memberid2
	
	1      F044-52-916  F04452916
	2      F19983915*   F19983915
	3      M63954321%   M63954321
	4      A79934#565@  A79934565
				

Print Document

Copyright © 2002-2004 www.nycinformatics®.com All Rights Reserved
Last edited on: May 28, 2006
SAS product or service names are registered trademarks of SAS Institute, Inc. in the USA and other countries.
® indicates USA registration.