Dear SAS Community,
I have been struggling with my SAS Program to add Clinical Classifications Software Refined (CCSR) for ICD-10 CM diagnosis on to my National Inpatient Sample (NIS) core dataset. I have modified all the parts of the program as instructed in the DXCCSR user guide. Unfortunately I keep getting error messages.
Please find below a sample of my modifications to the program and a snap shot of the error messages.
* FILE LOCATIONS ;
FILENAMe INRAW1 '/folders/myfolders/HCUP/NIS2018/DXCCSR_v2021-2.csv' lRECL=3000; *<=== USER MUST MODIFY;
LIBNAME IN1 '/folders/myfolders/HCUP/NIS2018'; *<=== USER MUST MODIFY;
LIBNAME OUT1 '/folders/myfolders/HCUP/NIS2018/NIS'; *<=== USER MUST MODIFY;
* OPTIONAL FILES ;
* Build vertical file? 1=yes, 0=no; %LET VERT=1; *<=== USER MUST MODIFY;
* Build default DXCCSR file? 1=yes, 0=no; %LET DFLT=1; *<=== USER MUST MODIFY;
* Build horizontal file? 1=yes, 0=no; %LET HORZ=0; *<=== USER MUST MODIFY;
* FILE NAMES ;
* Input SAS file member name; %LET CORE=NIS_2018_CORE; *<=== USER MUST MODIFY;
* Output SAS file name, vertical; %LET VERTFILE=NIS_CORE_OUTPUT_VERT; *<=== USER MUST MODIFY;
* Output SAS file name, horizontal; %LET HORZFILE=OUTPUT_HORZ_FILE_NAME; *<=== USER MUST MODIFY;
* Output SAS file name, default DXCCSR; %LET DFLTFILE=OUTPUT_DFLT_FILE_NAME; *<=== USER MUST MODIFY;
* INPUT DATA CHARACTERISTICS ;
* Database types, IP/OP/IO; %LET DBTYPE=IP; *<=== USER MUST MODIFY;
* Data element to identify IP/OP records; %LET IOVAR=DBTYPE; *<=== USER MUST MODIFY;
* Data value to identify IP records; %LET IOVALI=IP; *<=== USER MUST MODIFY;
* Data value to identify OP records; %LET IOVALO=OP; *<=== USER MUST;
* Linking key on input SAS data; %LET RECID=KEY; *<=== USER MUST MODIFY;
* Prefix of diagnosis variables; %LET DXPREFIX=I10_DX; *<=== USER MUST MODIFY;
* Maximum number of DXs on any record; %LET NUMDX=40; *<=== USER MUST MODIFY;
* Record specific DX Count variable, if not available leave it blank;
%LET NDXVAR=I10_NDX; *<=== USER MUST MODIFY;
Error Messages
ERROR: The variable KEY in the DROP, KEEP, or RENAME list has never been referenced.
ERROR: The variable DBTYPE in the DROP, KEEP, or RENAME list has never been referenced.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.NIS_2018_CORESKINNY may be incomplete. When this step was stopped there were 0 observations and 0
variables.
NOTE: PROCEDURE SORT used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds
ERROR: BY variable KEY is not on input data set WORK.NIS_2018_CORESKINNY.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.IP_IN may be incomplete. When this step was stopped there were 0 observations and 0 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
711:160 711:74
NOTE: Variable KEY is uninitialized.
NOTE: Variable I10_NDX is uninitialized.
ERROR: BY variable KEY is not on input data set WORK.IP_IN.
WARNING: The variable KEY in the DROP, KEEP, or RENAME list has never been referenced.
WARNING: The variable KEY in the DROP, KEEP, or RENAME list has never been referenced.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.IP_OUT_VT may be incomplete. When this step was stopped there were 0 observations and 4 variables.
WARNING: The data set WORK.DXCCSR_FLAGS may be incomplete. When this step was stopped there were 0 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.04 seconds
ERROR: The variable KEY in the DROP, KEEP, or RENAME list has never been referenced.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.IP_OUT_VT may be incomplete. When this step was stopped there were 0 observations and 4 variables.
WARNING: Data set WORK.IP_OUT_VT was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
ERROR: Variable KEY not found.
ERROR: BY variable KEY is not on input data set WORK.IP_OUT_VT.
ERROR: Variable KEY not found.
ERROR: Invalid value for the SORTEDBY option.
ERROR: The variable KEY in the DROP, KEEP, or RENAME list has never been referenced.
ERROR: BY variable KEY is not on input data set WORK.DXCCSR_FLAGS.
ERROR: BY variable KEY is not on input data set WORK.IP_DFLT_FILE.
ERROR: BY variable KEY is not on input data set WORK.IP_DFLT_FILE.
ERROR: Variable KEY not found.
ERROR: Invalid value for the SORTEDBY option.
Please does anyone know what might be wrong? I am quite new to SAS.
Also, if anyone has any experience using the NIS dataset, please hit me up.
Many thanks!
As shown in the following log, I think the problem is that in the first proc sort that creates WORK.NIS_2018_CORESKINNY, the non-existent variables KEY and DBTYPE are specified in the DROP, KEEP, or RENAME statements.
The following errors may be caused by the failure to create the dataset there, so could you please provide the program you ran and the sample data?
ERROR: The variable KEY in the DROP, KEEP, or RENAME list has never been referenced.
ERROR: The variable DBTYPE in the DROP, KEEP, or RENAME list has never been referenced.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.NIS_2018_CORESKINNY may be incomplete.When this step was stopped there were 0 observations and 0
variables.
NOTE: PROCEDURE SORT used (Total process time):
real time0.01 seconds
cpu time0.00 seconds
You need to supply a complete SAS log including both source code and error messages and notes. Post it using the </> icon. Without that we would just be guessing what your code does.
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 72 73 /******************************************************************/ 74 /* Title: CCSR FOR ICD-10-CM DIAGNOSIS MAPPING PROGRAM */ 75 /* */ 76 /* Program: DXCCSR_Mapping_Program_v2021-2.SAS */ 77 /* */ 78 /* Description: This is the SAS mapping program to apply */ 79 /* the CCSR to the user�s ICD-10-CM-coded data. */ 80 /* The mapping program includes two options */ 81 /* for the file structure of CCSR output. */ 82 /* */ 83 /* There are two general sections to this program: */ 84 /* */ 85 /* 1) The first section creates temporary SAS */ 86 /* informats using the DXCCSR CSV file. */ 87 /* These informats are used in step 2 to create */ 88 /* the CCSR variables in the output files. */ 89 /* output files. */ 90 /* 2) The second section loops through the diagnosis */ 91 /* array in your SAS dataset and assigns */ 92 /* CCSR categories in the output files. */ 93 /* */ 94 /* Starting with v2021-1 of the CCSR, the SAS program*/ 95 /* and accompanying CSV file include a separate */ 96 /* assignment of the default CCSR for inpatient data */ 97 /* (principal diagnosis) and outpatient data (first- */ 98 /* listed diagnosis). This feature requires that the */ 99 /* user identifies whether the input data is only */ 100 /* inpatient (IP), only outpatient (OP), or a */ 101 /* mixture of inpatient and outpatient data (IO). */ 102 /* The v2021-1 (and later) SAS program cannot be used*/ 103 /* with the prior versions of the DXCCSR CSV file. */ 104 /* */ 105 /* The v2021-2 CSV file is compatible with ICD-10-CM */ 106 /* diagnosis codes from October 2015 through */ 107 /* September 2021. */ 108 /* */ 109 /* Output: The program always outputs a vertical file. */ 110 /* + Vertical file's layout: RECID DXCCSR DX_POSITION*/ 111 /* DEFAULT_DXCCSR(Y, N, X, or Blank) */ 112 /* DXCCSR_VERSION */ 113 /* */ 114 /* The user can select to output two additional files*/ 115 /* + Horizontal file's layout: RECID DXCCSR_BBBNNN */ 116 /* DXCCSR_DEFAULT_DX1 DXCCSR_VERSION */ 117 /* where BBB=3-letter body system abbreviation, */ 118 /* NNN=3-digit number */ 119 /* + Default file's layout: RECID DXCCSR_DEFAULT_DX1 */ 120 /* DXCCSR_VERSION */ 121 /******************************************************************/ 122 123 /******************************************************************/ 124 /* Macro Variables that must be set to define the characteristics*/ 125 /* of your SAS discharge data. Change these values to match the */ 126 /* number of diagnoses in your dataset. Change CORE to match the */ 127 /* name of your dataset. Set DXPREFIX to be the fixed part of */ 128 /* the diagnosis variables. For example, if the diagnosis */ 129 /* variables in your SAS dataset are I10_DX1, I10_DX2, ... then */ 130 /* set DXPREFIX to I10_DX. */ 131 /******************************************************************/ 132 %Let obs_ = MAX; *<=== Use smaller number for testing; 133 134 * FILE LOCATIONS ; 135 FILENAMe INRAW1 '/folders/myfolders/HCUP/NIS2018/DXCCSR_v2021-2.csv' lRECL=3000; *<=== USER MUST MODIFY; 136 LIBNAME IN1 '/folders/myfolders/HCUP/NIS2018'; NOTE: Libref IN1 was successfully assigned as follows: Engine: V9 Physical Name: /folders/myfolders/HCUP/NIS2018 136 ! *<=== USER MUST MODIFY; 137 LIBNAME OUT1 '/folders/myfolders/HCUP/NIS2018/NIS'; NOTE: Libref OUT1 was successfully assigned as follows: Engine: V9 Physical Name: /folders/myfolders/HCUP/NIS2018/NIS 137 ! *<=== USER MUST MODIFY; 138 139 * OPTIONAL FILES ; 140 * Build vertical file? 1=yes, 0=no; %LET VERT=1; *<=== USER MUST MODIFY; 141 * Build default DXCCSR file? 1=yes, 0=no; %LET DFLT=0; *<=== USER MUST MODIFY; 142 * Build horizontal file? 1=yes, 0=no; %LET HORZ=0; *<=== USER MUST MODIFY; 143 144 * FILE NAMES ; 145 * Input SAS file member name; %LET CORE=NIS_2018_CORE; *<=== USER MUST MODIFY; 146 * Output SAS file name, vertical; %LET VERTFILE=NIS_CORE_OUTPUT_VERT; *<=== USER MUST MODIFY; 147 * Output SAS file name, horizontal; %LET HORZFILE=OUTPUT_HORZ_FILE_NAME; *<=== USER MUST MODIFY; 148 * Output SAS file name, default DXCCSR; %LET DFLTFILE=OUTPUT_DFLT_FILE_NAME; *<=== USER MUST MODIFY; 149 150 * INPUT DATA CHARACTERISTICS ; 151 * Database types, IP/OP/IO; %LET DBTYPE=IP; *<=== USER MUST MODIFY; 152 * Data element to identify IP/OP records; %LET IOVAR=DBTYPE; *<=== USER MUST MODIFY; 153 * Data value to identify IP records; %LET IOVALI=IP; *<=== USER MUST MODIFY; 154 * Data value to identify OP records; %LET IOVALO=OP; *<=== USER MUST; 155 * Linking key on input SAS data; %LET RECID=KEY; *<=== USER MUST MODIFY; 156 * Prefix of diagnosis variables; %LET DXPREFIX=I10_DX; *<=== USER MUST MODIFY; 157 * Maximum number of DXs on any record; %LET NUMDX=40; *<=== USER MUST MODIFY; 158 * Record specific DX Count variable, if not available leave it blank; 159 %LET NDXVAR=I10_NDX; *<=== USER MUST MODIFY; 160 161 TITLE1 'CREATE ICD-10-CM DXCCSR TOOL CATEGORIES'; 162 TITLE2 'USE WITH DISCHARGE ADMINISTRATIVE DATA THAT HAS ICD-10-CM CODES'; 163 164 /******************* SECTION 1: CREATE INFORMATS ****************************/ 165 /* SAS Load the CCSR CSV file & convert into temporary SAS informats that */ 166 /* will be used to assign the DXCCSR variables in the next step. */ 167 /****************************************************************************/ 168 %LET CCSRN_ = 6; 169 DATA DXCCSR; 170 LENGTH LABEL $1140; 171 INFILE INRAW1 DSD DLM=',' END = EOF FIRSTOBS=2; 172 INPUT 173 START : $CHAR7. 174 I10Label : $CHAR124. 175 I10CCSRDeftIP : $10. 176 I10CCSRLabelDeftIP: $CHAR228. 177 I10CCSRDeftOP : $10. 178 I10CCSRLabelDeftOP: $CHAR228. 179 I10CCSR1 : $10. 180 I10CCSRLabel1 : $CHAR228. 181 I10CCSR2 : $10. 182 I10CCSRLabel2 : $CHAR228. 183 I10CCSR3 : $10. 184 I10CCSRLabel3 : $CHAR228. 185 I10CCSR4 : $10. 186 I10CCSRLabel4 : $CHAR228. 187 I10CCSR5 : $10. 188 I10CCSRLabel5 : $CHAR228. 189 I10CCSR6 : $10. 190 I10CCSRLabel6 : $CHAR228. 191 ; 192 193 RETAIN HLO " " FMTNAME "$DXCCSR" TYPE "J" ; 194 195 LABEL = CATX("#", OF I10CCSR1-I10CCSR6, OF I10CCSRLabel1-I10CCSRLabel6) ; 196 OUTPUT; 197 198 IF EOF THEN DO ; 199 START = " " ; 200 LABEL = " " ; 201 HLO = "O"; 202 OUTPUT ; 203 END ; 204 RUN; NOTE: The infile INRAW1 is: Filename=/folders/myfolders/HCUP/NIS2018/DXCCSR_v2021-2.csv, Owner Name=root,Group Name=vboxsf, Access Permission=-rwxrwx---, Last Modified=04 March 2021 11:01:46, File Size (bytes)=20053092 NOTE: 73211 records were read from the infile INRAW1. The minimum record length was 93. The maximum record length was 594. NOTE: The data set WORK.DXCCSR has 73212 observations and 22 variables. NOTE: DATA statement used (Total process time): real time 0.51 seconds cpu time 0.37 seconds 205 206 PROC FORMAT LIB=WORK CNTLIN = DXCCSR; NOTE: Informat $DXCCSR is already on the library WORK.FORMATS. NOTE: Informat $DXCCSR has been output. 207 RUN; NOTE: PROCEDURE FORMAT used (Total process time): real time 0.18 seconds cpu time 0.19 seconds NOTE: There were 73212 observations read from the data set WORK.DXCCSR. 208 209 DATA DXCCSRL(KEEP=START LABEL FMTNAME TYPE HLO); 210 SET DXCCSR(KEEP=I10CCSR:) END=EOF; 211 212 RETAIN HLO " " FMTNAME "$DXCCSRL" TYPE "J" ; 213 214 ARRAY CCSRC(&CCSRN_) I10CCSR1-I10CCSR&CCSRN_; 215 ARRAY CCSRL(&CCSRN_) I10CCSRLabel1-I10CCSRLabel&CCSRN_; 216 217 LENGTH START $6 LABEL $228; 218 DO I=1 to &CCSRN_; 219 IF NOT MISSING(CCSRC(I)) then do; 220 START=CCSRC(I); 221 LABEL=CCSRL(I); 222 output; 223 end; 224 end; 225 226 IF EOF THEN DO ; 227 START = " " ; 228 LABEL = " " ; 229 HLO = "O"; 230 OUTPUT; 231 END; 232 run; NOTE: There were 73212 observations read from the data set WORK.DXCCSR. NOTE: The data set WORK.DXCCSRL has 83466 observations and 5 variables. NOTE: DATA statement used (Total process time): real time 0.07 seconds cpu time 0.07 seconds 233 234 PROC SORT DATA=DXCCSRL NODUPKEY; 235 BY START; 236 RUN; NOTE: There were 83466 observations read from the data set WORK.DXCCSRL. NOTE: 82925 observations with duplicate key values were deleted. NOTE: The data set WORK.DXCCSRL has 541 observations and 5 variables. NOTE: PROCEDURE SORT used (Total process time): real time 0.03 seconds cpu time 0.04 seconds 237 238 PROC FORMAT LIB=WORK CNTLIN = DXCCSRL; NOTE: Informat $DXCCSRL is already on the library WORK.FORMATS. NOTE: Informat $DXCCSRL has been output. 239 RUN; NOTE: PROCEDURE FORMAT used (Total process time): real time 0.00 seconds cpu time 0.00 seconds NOTE: There were 541 observations read from the data set WORK.DXCCSRL. 240 241 DATA DXCCSRDEFT(KEEP=START LABEL FMTNAME TYPE HLO); 242 SET DXCCSR(KEEP=START I10CCSRDeftIP rename=(I10CCSRDeftIP=LABEL)) END=EOF; 243 244 RETAIN HLO " " FMTNAME "$DXCCSRDIP" TYPE "J" ; 245 output; 246 IF EOF THEN DO ; 247 START = " " ; 248 LABEL = " " ; 249 HLO = "O"; 250 OUTPUT; 251 END; 252 run; NOTE: There were 73212 observations read from the data set WORK.DXCCSR. NOTE: The data set WORK.DXCCSRDEFT has 73213 observations and 5 variables. NOTE: DATA statement used (Total process time): real time 0.03 seconds cpu time 0.03 seconds 253 254 PROC SORT DATA=DXCCSRDEFT NODUPKEY; BY START; RUN; NOTE: There were 73213 observations read from the data set WORK.DXCCSRDEFT. NOTE: 1 observations with duplicate key values were deleted. NOTE: The data set WORK.DXCCSRDEFT has 73212 observations and 5 variables. NOTE: PROCEDURE SORT used (Total process time): real time 0.02 seconds cpu time 0.02 seconds 255 256 PROC FORMAT LIB=WORK CNTLIN = DXCCSRDEFT; NOTE: Informat $DXCCSRDIP is already on the library WORK.FORMATS. NOTE: Informat $DXCCSRDIP has been output. 257 RUN; NOTE: PROCEDURE FORMAT used (Total process time): real time 0.10 seconds cpu time 0.11 seconds NOTE: There were 73212 observations read from the data set WORK.DXCCSRDEFT. 258 259 DATA DXCCSRDEFT(KEEP=START LABEL FMTNAME TYPE HLO); 260 SET DXCCSR(KEEP=START I10CCSRDeftOP rename=(I10CCSRDeftOP=LABEL)) END=EOF; 261 262 RETAIN HLO " " FMTNAME "$DXCCSRDOP" TYPE "J" ; 263 output; 264 IF EOF THEN DO ; 265 START = " " ; 266 LABEL = " " ; 267 HLO = "O"; 268 OUTPUT; 269 END; 270 run; NOTE: There were 73212 observations read from the data set WORK.DXCCSR. NOTE: The data set WORK.DXCCSRDEFT has 73213 observations and 5 variables. NOTE: DATA statement used (Total process time): real time 0.03 seconds cpu time 0.03 seconds 271 272 PROC SORT DATA=DXCCSRDEFT NODUPKEY; BY START; RUN; NOTE: There were 73213 observations read from the data set WORK.DXCCSRDEFT. NOTE: 1 observations with duplicate key values were deleted. NOTE: The data set WORK.DXCCSRDEFT has 73212 observations and 5 variables. NOTE: PROCEDURE SORT used (Total process time): real time 0.02 seconds cpu time 0.02 seconds 273 274 PROC FORMAT LIB=WORK CNTLIN = DXCCSRDEFT; NOTE: Informat $DXCCSRDOP is already on the library WORK.FORMATS. NOTE: Informat $DXCCSRDOP has been output. 275 RUN; NOTE: PROCEDURE FORMAT used (Total process time): real time 0.09 seconds cpu time 0.09 seconds NOTE: There were 73212 observations read from the data set WORK.DXCCSRDEFT. 276 277 /*********** SECTION 2: CREATE ICD-10-CM CCSR OUTPUT FILES ***********************/ 278 /* Create CCSR categories for ICD-10-CM using the SAS informats created */ 279 /* in Section 1 and the diagnosis codes in your SAS dataset. */ 280 /* At most three separate output files are created plus a few intermediate files*/ 281 /* for the construction of the horizontal and default DXCCSR for DX1 file */ 282 /*********************************************************************************/ 283 284 %Macro dxccsr_vt(dbt=IP); 285 DATA &dbt._out_vt (KEEP=&RECID DXCCSR DX_POSITION DEFAULT_DXCCSR DXCCSR_VERSION) 286 dxccsr_flags (keep=&RECID flag_anydx flag_xxx flag_dx1) 287 ; 288 retain &RECID; 289 LENGTH ICD10_Code $7 DXCCSR $6 DX_POSITION 3 DEFAULT_DXCCSR $1 DXCCSR_VERSION $6 flag_xxx $6; 290 LABEL DEFAULT_DXCCSR = "Indication of default CCSR for principal/first-listed ICD-10-CM diagnosis" 291 DXCCSR = "CCSR category for ICD-10-CM diagnosis" 292 DX_POSITION = "Position of code in input diagnosis array" 293 DXCCSR_VERSION = "Version of CCSR for ICD-10-CM diagnoses" 294 ; 295 296 SET &dbt._in; 297 by &RECID; 298 retain DXCCSR_VERSION "2021.2"; 299 array A_DX(&NUMDX) &DXPREFIX.1-&DXPREFIX.&NUMDX; 300 301 %if &NDXVAR ne %then %let MAXNDX = &NDXVAR; 302 %else %let MAXNDX=&NUMDX; 303 304 flag_anydx =0; &dbt.flag_xxx=''; flag_dx1=0; 305 if not missing(&DXPREFIX.1) then flag_dx1=1; 306 307 DO I=1 TO min(&MAXNDX, dim(A_dx)); 308 ICD10_CODE=A_DX(I); 309 DX_POSITION=I; 310 Default_DCCSR_Val =input(ICD10_CODE, $DXCCSRD&dbt..); 311 312 if ICD10_CODE ^= '' then flag_anydx=1; 313 314 CCSRString=INPUT(A_DX(I), $DXCCSR.); 315 if not missing(ICD10_CODE) and missing(CCSRString) then do; 316 ***invalid diagnosis found; 317 DXCCSR='InvlDX'; 318 if I= 1 then DEFAULT_DXCCSR = 'X'; 319 else DEFAULT_DXCCSR = ''; 320 output &dbt._out_vt; 321 end; 322 else if not missing(CCSRString) then do; 323 ccsrn=(COUNTC(CCSRString,'#')+1)/2; 324 if ccsrn=1 then do; 325 next_delim = findc(CCSRString,"#"); 326 DXCCSR=substr(CCSRString,1, next_delim-1); 327 328 if I=1 then do; 329 if Default_DCCSR_Val = DXCCSR then DEFAULT_DXCCSR = 'Y'; 330 else if Default_DCCSR_Val =: 'XXX' then do; 331 DEFAULT_DXCCSR = 'X'; 332 flag_xxx=Default_DCCSR_Val; 333 end; 334 else DEFAULT_DXCCSR = 'N'; 335 end; 336 else DEFAULT_DXCCSR = ''; 337 338 output &dbt._out_vt; 339 end; 340 else do; 341 do j=1 to ccsrn; 342 next_delim = findc(CCSRString,"#"); 343 DXCCSR=substr(CCSRString,1, next_delim-1); 344 CCSRString=substr(CCSRString,next_delim+1); 345 346 if I=1 then do; 347 if Default_DCCSR_Val = DXCCSR then DEFAULT_DXCCSR = 'Y'; 348 else if Default_DCCSR_Val =: 'XXX' then do; 349 DEFAULT_DXCCSR = 'X'; 350 flag_xxx=Default_DCCSR_Val; 351 end; 352 else DEFAULT_DXCCSR = 'N'; 353 end; 354 else DEFAULT_DXCCSR = ''; 355 356 output &dbt._out_vt; 357 end; 358 do j=1 to ccsrn-1; 359 next_delim = findc(CCSRString,"#"); 360 CCSRString=substr(CCSRString,next_delim+1); 361 end; /*do j*/ 362 end; /*else do*/ 363 end; /*not missing CCSString*/ 364 end; /*loop i*/ 365 366 output dxccsr_flags; 367 run; 368 369 /*If DX1 is missing add it to the vertical file*/ 370 data &dbt._out_vt; 371 merge &dbt._out_vt(in=inv) 372 dxccsr_flags(in=inf keep=&RECID flag_dx1) 373 ; 374 by &RECID; 375 if inf and not inv then do; 376 DXCCSR='NoDX1'; 377 DX_POSITION=1; 378 DEFAULT_DXCCSR='X'; 379 DXCCSR_VERSION="2021.2"; 380 output; 381 end; 382 else if flag_dx1=0 then do; 383 output; 384 ***there may be multiple diagnosis on vertical file, output NoDX1 only once; 385 if first.&RECID then do; 386 DXCCSR='NoDX1'; 387 DX_POSITION=1; 388 DEFAULT_DXCCSR='X'; 389 output; 390 end; 391 end; 392 else output; 393 drop flag_dx1; 394 run; 395 396 proc sort data=&dbt._out_vt; by &RECID DX_POSITION; run; 397 398 Title1 "Vertical file"; 399 proc contents data=&dbt._out_vt varnum; 400 run; 401 Title2 "Sample print of vertical file"; 402 proc print data=&dbt._out_vt (obs=10); 403 run; 404 %mend; 405 406 * =========================================================================== * 407 * Count maximum number of DXCCSR values for each body system. 408 * Please do not change this code. It is necessary to the program function. 409 * =========================================================================== *; 410 %macro count_ccsr; 411 DATA Body_sys; 412 length body bnum $3 ; 413 INFILE INRAW1 DSD DLM=',' END = EOF FIRSTOBS=2; 414 INPUT 415 START : $CHAR7. 416 I10Label : $CHAR124. 417 I10CCSRDeftIP : $10. 418 I10CCSRLabelDeftIP: $CHAR228. 419 I10CCSRDeftOP : $10. 420 I10CCSRLabelDeftOP: $CHAR228. 421 I10CCSR1 : $10. 422 I10CCSRLabel1 : $CHAR228. 423 I10CCSR2 : $10. 424 I10CCSRLabel2 : $CHAR228. 425 I10CCSR3 : $10. 426 I10CCSRLabel3 : $CHAR228. 427 I10CCSR4 : $10. 428 I10CCSRLabel4 : $CHAR228. 429 I10CCSR5 : $10. 430 I10CCSRLabel5 : $CHAR228. 431 I10CCSR6 : $10. 432 I10CCSRLabel6 : $CHAR228. 433 ; 434 435 array ccsrs I10CCSR1-I10CCSR6; 436 do over ccsrs; 437 body=substr(ccsrs, 1, 3); 438 bnum=substr(ccsrs, 4, 3); 439 if body not in ('', 'XXX') then output; 440 end; 441 keep body bnum; 442 run; 443 proc sort data=Body_sys; by body bnum ; run; 444 data body_max; 445 set body_sys; 446 by body bnum; 447 if last.body; 448 run; 449 %global mnbody; 450 %global body_; 451 proc sql noprint; 452 select distinct body into :body_ separated by ' ' 453 from body_max 454 ; 455 quit; 456 data null; 457 set body_max end=eof; 458 if eof then call symput("mnbody", put(_N_, 2.)); 459 run; 460 461 %do i=1 %to &mnbody; 462 %let b=%scan(&body_, &i); 463 %global max&b. ; 464 %end; 465 466 data null; 467 set body_max end=eof; 468 mbody="max" || body; 469 call symput(mbody, bnum); 470 if eof then call symput("mnbody", put(_N_, 2.)); 471 run; 472 473 %put verify macro definition:; 474 %put mnbody=&mnbody; 475 %do i=1 %to &mnbody; 476 %let b=%scan(&body_, &i); 477 %put max&b._ = &&&max&b; 478 %end; 479 %mend; 480 481 %macro dxccsr_hz(dbt=IP); 482 * =========================================================================== * 483 * Create horizontal file layout using vertical file * 484 * =========================================================================== *; 485 Data DXCCSR_First(keep=&RECID DXCCSR) DXCCSR_second(keep=&RECID DXCCSR); 486 set &dbt._out_vt; 487 by &RECID; 488 if DXCCSR not in ('InvlDX', 'NoDX1'); 489 if DX_Position = 1 then output DXCCSR_First; 490 else output DXCCSR_Second; 491 run; 492 493 proc sort data=DXCCSR_second nodupkey; 494 by &RECID DXCCSR; 495 run; 496 proc sort data=DXCCSR_First; 497 by &RECID DXCCSR; 498 run; 499 500 data DXCCSR; 501 length DX_Position 3; 502 merge DXCCSR_First(in=inp) DXCCSR_Second(in=ins); 503 by &RECID DXCCSR; 504 if inp and not ins then DX_Position = 1; 505 else if ins and not inp then DX_Position = 3; 506 else DX_Position = 2; 507 run; 508 509 proc transpose data=DXCCSR out=DXCCSR_Transposed(drop=_NAME_) prefix=DXCCSR_; 510 by &RECID; 511 ID DXCCSR; 512 Var DX_Position; 513 run; 514 515 **** Ensure the horizontal output file has the same number of records as input file; 516 data &dbt._out_hz ; 517 retain &RECID; 518 LENGTH DXCCSR_Default_DX1 $6; 519 LENGTH 520 %do i=1 %to &mnbody; 521 %let b=%scan(&body_, &i); 522 DXCCSR_&b.001-DXCCSR_&b.&&max&b. 523 %end; 524 3 ; 525 Label 526 %do i=1 %to &mnbody; 527 %let b=%scan(&body_, &i); 528 %do j=1 %to &&max&b.; 529 %if &j < 10 %then DXCCSR_&b.00&j = "Indication that at least one ICD-10-CM diagnosis on the record is included in 529 ! CCSR &b.00&j" ; 530 %else %if &j < 100 %then DXCCSR_&b.0&j = "Indication that at least one ICD-10-CM diagnosis on the record is 530 ! included in CCSR &b.0&j" ; 531 %else DXCCSR_&b.&j = "Indication that at least one ICD-10-CM diagnosis on the record is included in CCSR &b.&j" ; 532 %end; 533 %end; 534 ; 535 merge &dbt._dflt_file(in=ind) DXCCSR_Transposed ; 536 by &RECID; 537 if not ind then abort; ***Should never happen but safe guard, default file contains all records from input file; 538 539 ***If no diagnoses are found on the record, set all DXCCSR_* values to 0; 540 array a _numeric_; 541 do over a; 542 if a = . then a=0; 543 end; 544 drop DXCCSR_MBD015 DXCCSR_MBD016; 545 run; 546 547 Title1 "Horizontal file"; 548 proc contents data=&dbt._out_hz varnum; 549 run; 550 Title2 "Sample print of horizontal file"; 551 proc print data=&dbt._out_hz(obs=10); 552 run; 553 %mend; 554 555 %macro dxccsr_dflt(dbt=IP); 556 * ================================================================================= * 557 * Create the default CCSR file with RECID & Default DXCCSR value using vertical file* 558 * ================================================================================= *; 559 data &dbt._dflt_file(keep=&RECID DXCCSR_DEFAULT_DX1); 560 length DXCCSR_DEFAULT_DX1 $6; 561 set &dbt._out_vt(keep=&RECID DX_POSITION DXCCSR DEFAULT_DXCCSR); 562 by &RECID; 563 564 if DX_POSITION = 1 and DEFAULT_DXCCSR in ('Y'); 565 DXCCSR_DEFAULT_DX1 = DXCCSR; 566 run; 567 568 **** Ensure the default DXCCSR output file has the same number of records as input file; 569 Data &dbt._dflt_file; 570 retain &RECID; 571 length DXCCSR_DEFAULT_DX1 DXCCSR_VERSION $6; 572 label DXCCSR_DEFAULT_DX1 = "Default CCSR for principal/first-listed ICD-10-CM diagnosis" 573 DXCCSR_VERSION = "Version of CCSR for ICD-10-CM diagnoses" 574 ; 575 merge dxccsr_flags(in=ini) 576 &dbt._dflt_file(in=ino) ; 577 by &RECID; 578 retain DXCCSR_VERSION "2021.2"; 579 580 if not ini then abort; 581 if not ino then do; 582 if not flag_dx1 then DXCCSR_DEFAULT_DX1 = 'NoDX1'; 583 else if flag_xxx ^='' then DXCCSR_DEFAULT_DX1 = flag_xxx; 584 else if flag_anydx then DXCCSR_DEFAULT_DX1 = 'InvlDX'; 585 end; 586 drop flag_anydx flag_xxx flag_dx1; 587 run; 588 589 %mend; 590 591 %macro main; 592 %count_ccsr; 593 proc sort data=IN1.&CORE(obs=&obs_ keep=&RECID &NDXVAR &DXPREFIX.1-&DXPREFIX.&NUMDX %if &dbtype ne and &IOVAR ne %then 593 ! &IOVAR;) out=&CORE.Skinny; by &RECID; run; 594 %if &DBTYPE = IO %then %do; 595 %if &IOVAR NE %then %do; 596 data IP_in OP_in NIO; 597 set &CORE.Skinny; 598 by &RECID; 599 if &IOVAR = "&IOValI" then output IP_in; 600 else if &IOVAR = "&IOValO" then output OP_in; 601 else output NIO; 602 run; 603 604 %dxccsr_vt(dbt=IP); 605 %dxccsr_dflt(dbt=IP); 606 %dxccsr_vt(dbt=OP); 607 %dxccsr_dflt(dbt=OP); 608 %if &vert = 1 %then %do; 609 data OUT1.&VERTFILE(SortedBy=&RECID); 610 set IP_out_vt OP_out_vt; 611 by &RECID; 612 run; 613 %end; 614 %if &dflt = 1 %then %do; 615 data OUT1.&DFLTFILE(SortedBy=&RECID); 616 set IP_dflt_file OP_dflt_file NIO(keep=&RECID); 617 by &RECID; 618 run; 619 620 Title1 "Default DXCCSR file"; 621 proc contents data=OUT1.&DFLTFILE; 622 run; 623 Title2 "Sample print of default DXCCSR file"; 624 proc print data=OUT1.&DFLTFILE(obs=10); 625 run; 626 %end; 627 %if &horz = 1 %then %do; 628 %dxccsr_hz(dbt=IP); 629 %dxccsr_hz(dbt=OP); 630 data out1.&HORZFILE(SortedBy=&RECID); 631 set IP_out_hz OP_out_hz NIO(keep=&RECID); 632 by &RECID; 633 run; 634 635 %end; 636 %end; 637 %else ERROR 'IOVAR is not specified'; 638 %end; 639 %else %if &DBTYPE = IP %then %do; 640 data IP_in; 641 set &CORE.Skinny; 642 by &RECID; 643 run; 644 645 %dxccsr_vt(dbt=IP); 646 %if &vert = 1 %then %do; 647 data OUT1.&VERTFILE(SortedBy=&RECID); 648 set IP_out_vt; 649 by &RECID; 650 run; 651 %end; 652 %dxccsr_dflt(dbt=IP); 653 %if &dflt = 1 %then %do; 654 data OUT1.&DFLTFILE(SortedBy=&RECID); 655 set IP_dflt_file; 656 by &RECID; 657 run; 658 659 Title1 "Default DXCCSR file"; 660 proc contents data=OUT1.&DFLTFILE; 661 run; 662 Title2 "Sample print of default DXCCSR file"; 663 proc print data=OUT1.&DFLTFILE(obs=10); 664 run; 665 %end; 666 %if &horz = 1 %then %do; 667 %dxccsr_hz(dbt=IP); 668 data out1.&HORZFILE(SortedBy=&RECID); 669 set IP_out_hz; 670 by &RECID; 671 run; 672 %end; 673 %end; 674 %else %if &DBTYPE = OP %then %do; 675 data OP_in; 676 set &CORE.Skinny; 677 by &RECID; 678 run; 679 680 %dxccsr_vt(dbt=OP); 681 %if &vert = 1 %then %do; 682 data OUT1.&VERTFILE(SortedBy=&RECID); 683 set OP_out_vt; 684 by &RECID; 685 run; 686 %end; 687 %dxccsr_dflt(dbt=OP); 688 %if &dflt = 1 %then %do; 689 data OUT1.&DFLTFILE(SortedBy=&RECID); 690 set OP_dflt_file; 691 by &RECID; 692 run; 693 694 Title1 "Default DXCCSR file"; 695 proc contents data=OUT1.&DFLTFILE; 696 run; 697 Title2 "Sample print of default DXCCSR file"; 698 proc print data=OUT1.&DFLTFILE(obs=10); 699 run; 700 %end; 701 %if &horz = 1 %then %do; 702 %dxccsr_hz(dbt=OP); 703 data out1.&HORZFILE(SortedBy=&RECID); 704 set OP_out_hz; 705 by &RECID; 706 run; 707 %end; 708 %end; 709 710 %mend; 711 %main; NOTE: The infile INRAW1 is: Filename=/folders/myfolders/HCUP/NIS2018/DXCCSR_v2021-2.csv, Owner Name=root,Group Name=vboxsf, Access Permission=-rwxrwx---, Last Modified=04 March 2021 11:01:46, File Size (bytes)=20053092 NOTE: 73211 records were read from the infile INRAW1. The minimum record length was 93. The maximum record length was 594. NOTE: The data set WORK.BODY_SYS has 83464 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.16 seconds cpu time 0.15 seconds NOTE: There were 83464 observations read from the data set WORK.BODY_SYS. NOTE: The data set WORK.BODY_SYS has 83464 observations and 2 variables. NOTE: PROCEDURE SORT used (Total process time): real time 0.02 seconds cpu time 0.03 seconds NOTE: There were 83464 observations read from the data set WORK.BODY_SYS. NOTE: The data set WORK.BODY_MAX has 21 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.01 seconds NOTE: PROCEDURE SQL used (Total process time): real time 0.00 seconds cpu time 0.00 seconds NOTE: There were 21 observations read from the data set WORK.BODY_MAX. NOTE: The data set WORK.NULL has 21 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds NOTE: There were 21 observations read from the data set WORK.BODY_MAX. NOTE: The data set WORK.NULL has 21 observations and 3 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds verify macro definition: mnbody=21 maxBLD_ = 010 maxCIR_ = 039 maxDIG_ = 025 maxEAR_ = 006 maxEND_ = 017 maxEXT_ = 030 maxEYE_ = 012 maxFAC_ = 025 maxGEN_ = 026 maxINF_ = 012 maxINJ_ = 076 maxMAL_ = 010 maxMBD_ = 034 maxMUS_ = 038 maxNEO_ = 074 maxNVS_ = 022 maxPNL_ = 015 maxPRG_ = 030 maxRSP_ = 017 maxSKN_ = 007 maxSYM_ = 017 ERROR: The variable KEY in the DROP, KEEP, or RENAME list has never been referenced. ERROR: The variable DBTYPE in the DROP, KEEP, or RENAME list has never been referenced. NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set WORK.NIS_2018_CORESKINNY may be incomplete. When this step was stopped there were 0 observations and 0 variables. WARNING: Data set WORK.NIS_2018_CORESKINNY was not replaced because this step was stopped. NOTE: PROCEDURE SORT used (Total process time): real time 0.01 seconds cpu time 0.02 seconds ERROR: BY variable KEY is not on input data set WORK.NIS_2018_CORESKINNY. NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set WORK.IP_IN may be incomplete. When this step was stopped there were 0 observations and 0 variables. WARNING: Data set WORK.IP_IN was not replaced because this step was stopped. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column). 711:160 711:74 NOTE: Variable KEY is uninitialized. NOTE: Variable I10_NDX is uninitialized. ERROR: BY variable KEY is not on input data set WORK.IP_IN. WARNING: The variable KEY in the DROP, KEEP, or RENAME list has never been referenced. WARNING: The variable KEY in the DROP, KEEP, or RENAME list has never been referenced. NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set WORK.IP_OUT_VT may be incomplete. When this step was stopped there were 0 observations and 4 variables. WARNING: Data set WORK.IP_OUT_VT was not replaced because this step was stopped. WARNING: The data set WORK.DXCCSR_FLAGS may be incomplete. When this step was stopped there were 0 observations and 3 variables. WARNING: Data set WORK.DXCCSR_FLAGS was not replaced because this step was stopped. NOTE: DATA statement used (Total process time): real time 0.03 seconds cpu time 0.02 seconds ERROR: The variable KEY in the DROP, KEEP, or RENAME list has never been referenced. NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set WORK.IP_OUT_VT may be incomplete. When this step was stopped there were 0 observations and 4 variables. WARNING: Data set WORK.IP_OUT_VT was not replaced because this step was stopped. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds ERROR: Variable KEY not found. NOTE: The SAS System stopped processing this step because of errors. NOTE: PROCEDURE SORT used (Total process time): real time 0.00 seconds cpu time 0.00 seconds NOTE: PROCEDURE CONTENTS used (Total process time): real time 0.05 seconds cpu time 0.04 seconds NOTE: No observations in data set WORK.IP_OUT_VT. NOTE: PROCEDURE PRINT used (Total process time): real time 0.00 seconds cpu time 0.00 seconds ERROR: BY variable KEY is not on input data set WORK.IP_OUT_VT. ERROR: Variable KEY not found. ERROR: Invalid value for the SORTEDBY option. NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set OUT1.NIS_CORE_OUTPUT_VERT may be incomplete. When this step was stopped there were 0 observations and 0 variables. WARNING: Data set OUT1.NIS_CORE_OUTPUT_VERT was not replaced because this step was stopped. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.00 seconds ERROR: The variable KEY in the DROP, KEEP, or RENAME list has never been referenced. WARNING: The variable KEY in the DROP, KEEP, or RENAME list has never been referenced. NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set WORK.IP_DFLT_FILE may be incomplete. When this step was stopped there were 0 observations and 1 variables. WARNING: Data set WORK.IP_DFLT_FILE was not replaced because this step was stopped. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds NOTE: Variable KEY is uninitialized. ERROR: BY variable KEY is not on input data set WORK.DXCCSR_FLAGS. ERROR: BY variable KEY is not on input data set WORK.IP_DFLT_FILE. NOTE: The SAS System stopped processing this step because of errors. WARNING: The data set WORK.IP_DFLT_FILE may be incomplete. When this step was stopped there were 0 observations and 2 variables. WARNING: Data set WORK.IP_DFLT_FILE was not replaced because this step was stopped. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.01 seconds 712 713 714 715 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 727
This is the error message I get
Check if the variables KEY and DBTYPE are present in the dataset named IN1.NIS_2018_CORE.
The 'IN1.NIS_2018_Core' dataset has 'KEY_NIS' as the identifier not 'KEY.' However, the load program for DXCCSR ICD-10 has KEY, which is very odd. DBTYPE is not present.
For IN1.&CORE in this proc Step, the variables KEY (macro variable: &RECID) and DBTYPE (macro variable: IOVAR) are specified in the keep=dataset option, so it is not processed correctly.
proc sort data=IN1.&CORE(obs=&obs_ keep=&RECID &NDXVAR &DXPREFIX.1-&DXPREFIX.&NUMDX %if &dbtype ne and &IOVAR ne %then &IOVAR;) out=&CORE.Skinny; by &RECID; run;
I don't know if the problem is with the original data, the program, or the macro variable specification.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.