Hi all
I have just experienced a weird situation that I cannot find documentation on.
The focus is on the log, which is really all you should need, but because I know _someone_ is going to complain about me not posting code, consider these two SAS statements:
PROC EXPORT DATA=CHE.cohort
(WHERE=(InAPDC) KEEP=PPN NumRecsPerCaseAPDC InAPDC NumRecsPerCaseCOD InCOD NumRecsPerCaseRBDM InRBDM APDC_TXY_case N_APDC_TXY_events COD_TXY_case PoisoningSubcohort Sex BirthDate death_dateCOD death_dateRBDM)
OUTFILE="l:\Cohort.csv"
DBMS=CSV
REPLACE;
RUN;
PROC EXPORT DATA=CHE.cohort
(KEEP=PPN NumRecsPerCaseAPDC InAPDC NumRecsPerCaseCOD InCOD NumRecsPerCaseRBDM InRBDM APDC_TXY_case N_APDC_TXY_events COD_TXY_case PoisoningSubcohort Sex BirthDate death_dateCOD death_dateRBDM
WHERE=(InAPDC))
OUTFILE="l:\Cohort.csv"
DBMS=CSV
REPLACE;
RUN;
The only difference is that in the first, the WHERE statement is before the KEEP and after in the second.
Now look at the two logs below.
For the first PROC EXPORT statement, the first variable (ppn) is not exported. I can't understand why the placement of the WHERE statement should cause one variable to be dropped?
Has anyone seen this, or can explain it?
1271 PROC EXPORT DATA=CHE.COHORT
1272 (WHERE=(InAPDC) KEEP=PPN NumRecsPerCaseAPDC InAPDC NumRecsPerCaseCOD InCOD
1272! NumRecsPerCaseRBDM InRBDM APDC_TXY_case N_APDC_TXY_events COD_TXY_case PoisoningSubcohort Sex
1272! BirthDate death_dateCOD death_dateRBDM)
1273 OUTFILE="l:\Cohort.csv"
1274 DBMS=CSV
1275 REPLACE;
1276 RUN;
1277 /**********************************************************************
1278 * PRODUCT: SAS
1279 * VERSION: 9.4
1280 * CREATOR: External File Interface
1281 * DATE: 27MAY26
1282 * DESC: Generated SAS Datastep Code
1283 * TEMPLATE SOURCE: (None Specified.)
1284 ***********************************************************************/
1285 data _null_;
1286 %let _EFIERR_ = 0; /* set the ERROR detection macro variable */
1287 %let _EFIREC_ = 0; /* clear export record count macro variable */
1288 file 'l:\Cohort.csv' delimiter=',' DSD DROPOVER
1288! lrecl=32767;
1289 if _n_ = 1 then /* write column names or labels */
1290 do;
1291 put
1292 ','
1293 "NumRecsPerCaseAPDC"
1294 ','
1295 "InAPDC"
1296 ','
1297 "NumRecsPerCaseCOD"
1298 ','
1299 "InCOD"
1300 ','
1301 "NumRecsPerCaseRBDM"
1302 ','
1303 "InRBDM"
1304 ','
1305 "APDC_TXY_case"
1306 ','
1307 "N_APDC_TXY_events"
1308 ','
1309 "COD_TXY_case"
1310 ','
1311 "PoisoningSubcohort"
1312 ','
1313 "Sex"
1314 ','
1315 "BirthDate"
1316 ','
1317 "death_dateCOD"
1318 ','
1319 "death_dateRBDM"
1320 ;
1321 end;
1322 set CHE.COHORT(WHERE=(InAPDC) KEEP=PPN NumRecsPerCaseAPDC InAPDC
1322! NumRecsPerCaseCOD InCOD NumRecsPerCaseRBDM InRBDM APDC_TXY_case N_APDC_TXY_events
1322! COD_TXY_case PoisoningSubcohort Sex
1323 BirthDate death_dateCOD death_dateRBDM) end=EFIEOD;
1324 format NumRecsPerCaseAPDC best12. ;
1325 format InAPDC best12. ;
1326 format NumRecsPerCaseCOD best12. ;
1327 format InCOD best12. ;
1328 format NumRecsPerCaseRBDM best12. ;
1329 format InRBDM best12. ;
1330 format APDC_TXY_case best12. ;
1331 format N_APDC_TXY_events best12. ;
1332 format COD_TXY_case best12. ;
1333 format PoisoningSubcohort best12. ;
1334 format Sex bestx12. ;
1335 format BirthDate date9. ;
1336 format death_dateCOD date9. ;
1337 format death_dateRBDM date9. ;
1338 do;
1339 EFIOUT + 1;
1340 put NumRecsPerCaseAPDC @;
1341 put InAPDC @;
1342 put NumRecsPerCaseCOD @;
1343 put InCOD @;
1344 put NumRecsPerCaseRBDM @;
1345 put InRBDM @;
1346 put APDC_TXY_case @;
1347 put N_APDC_TXY_events @;
1348 put COD_TXY_case @;
1349 put PoisoningSubcohort @;
1350 put Sex @;
1351 put BirthDate @;
1352 put death_dateCOD @;
1353 put death_dateRBDM ;
1354 ;
1355 end;
1356 if _ERROR_ then call symputx('_EFIERR_',1); /* set ERROR detection macro variable */
1357 if EFIEOD then call symputx('_EFIREC_',EFIOUT);
1358 run;
1372 PROC EXPORT DATA=CHE.cohort
1373 (KEEP=PPN NumRecsPerCaseAPDC InAPDC NumRecsPerCaseCOD InCOD
1373! NumRecsPerCaseRBDM InRBDM APDC_TXY_case N_APDC_TXY_events COD_TXY_case PoisoningSubcohort Sex
1373! BirthDate death_dateCOD death_dateRBDM
1374 WHERE=(InAPDC))
1375 OUTFILE="l:\Cohort.csv"
1376 DBMS=CSV
1377 REPLACE;
1378 RUN;
1379 /**********************************************************************
1380 * PRODUCT: SAS
1381 * VERSION: 9.4
1382 * CREATOR: External File Interface
1383 * DATE: 27MAY26
1384 * DESC: Generated SAS Datastep Code
1385 * TEMPLATE SOURCE: (None Specified.)
1386 ***********************************************************************/
1387 data _null_;
1388 %let _EFIERR_ = 0; /* set the ERROR detection macro variable */
1389 %let _EFIREC_ = 0; /* clear export record count macro variable */
1390 file 'l:\Cohort.csv' delimiter=',' DSD DROPOVER
1390! lrecl=32767;
1391 if _n_ = 1 then /* write column names or labels */
1392 do;
1393 put
1394 "PPN"
1395 ','
1396 "NumRecsPerCaseAPDC"
1397 ','
1398 "InAPDC"
1399 ','
1400 "NumRecsPerCaseCOD"
1401 ','
1402 "InCOD"
1403 ','
1404 "NumRecsPerCaseRBDM"
1405 ','
1406 "InRBDM"
1407 ','
1408 "APDC_TXY_case"
1409 ','
1410 "N_APDC_TXY_events"
1411 ','
1412 "COD_TXY_case"
1413 ','
1414 "PoisoningSubcohort"
1415 ','
1416 "Sex"
1417 ','
1418 "BirthDate"
1419 ','
1420 "death_dateCOD"
1421 ','
1422 "death_dateRBDM"
1423 ;
1424 end;
1425 set CHE.COHORT(KEEP=PPN NumRecsPerCaseAPDC InAPDC NumRecsPerCaseCOD InCOD
1425! NumRecsPerCaseRBDM InRBDM APDC_TXY_case N_APDC_TXY_events COD_TXY_case PoisoningSubcohort Sex
1425! BirthDate
1426 death_dateCOD death_dateRBDM WHERE=(InAPDC)) end=EFIEOD;
1427 format PPN $14. ;
1428 format NumRecsPerCaseAPDC best12. ;
1429 format InAPDC best12. ;
1430 format NumRecsPerCaseCOD best12. ;
1431 format InCOD best12. ;
1432 format NumRecsPerCaseRBDM best12. ;
1433 format InRBDM best12. ;
1434 format APDC_TXY_case best12. ;
1435 format N_APDC_TXY_events best12. ;
1436 format COD_TXY_case best12. ;
1437 format PoisoningSubcohort best12. ;
1438 format Sex bestx12. ;
1439 format BirthDate date9. ;
1440 format death_dateCOD date9. ;
1441 format death_dateRBDM date9. ;
1442 do;
1443 EFIOUT + 1;
1444 put PPN $ @;
1445 put NumRecsPerCaseAPDC @;
1446 put InAPDC @;
1447 put NumRecsPerCaseCOD @;
1448 put InCOD @;
1449 put NumRecsPerCaseRBDM @;
1450 put InRBDM @;
1451 put APDC_TXY_case @;
1452 put N_APDC_TXY_events @;
1453 put COD_TXY_case @;
1454 put PoisoningSubcohort @;
1455 put Sex @;
1456 put BirthDate @;
1457 put death_dateCOD @;
1458 put death_dateRBDM ;
1459 ;
1460 end;
1461 if _ERROR_ then call symputx('_EFIERR_',1); /* set ERROR detection macro variable */
1462 if EFIEOD then call symputx('_EFIREC_',EFIOUT);
1463 run;
This looks like some kind of a bug, report it to SAS tech support.
Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.
Explore Now →Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.