BookmarkSubscribeRSS Feed
mauri0623
Quartz | Level 8

I need help with creating a macro that can loop through six different .DAT files and make six SAS dataset from them. Below is the code.

MCD-0190-201812-001.DAT
MCD-0191-201812-001.DAT
MCD-0192-201812-001.DAT
MCD-0193-201812-001.DAT
MCD-0194-201812-001.DAT
MCD-0198-201812-001.DAT

I have the above six files that I want to make a SAS dataset from them. Not one at a time but all of then in one macro.How do I build this macro that
can read one file at a time and make a SAS dataset out of them?


Data MCD;

infile "&filename." truncover firstobs=2 END=EOF LRECl=564 missover;

LENGTH ENCTR_TYP_CD /*sequence*/ DRG_CD $3.
MAJ_SPCL_CD INST_TYP_CD $2. ;
;

FORMAT sbmt_rec_idx_nbr z11. sequence 8.
COST 11.2 COPAY 7.2 DW_LD_RUN_ID DW_UPDT_RUN_ID 8.
REL_ADMIS_DT REL_DISP_DT
DW_SYS_EFF_DT DW_SYS_END_DT
SRVC_1_START_DT SRVC_1_END_DT
SRVC_2_START_DT SRVC_2_END_DT
SRVC_3_START_DT SRVC_3_END_DT
SRVC_4_START_DT SRVC_4_END_DT
SRVC_5_START_DT SRVC_5_END_DT
SRVC_6_START_DT SRVC_6_END_DT
HOSP_SRV_ADMIS_DT HOSP_SRV_DISP_DT yymmddn8. ;

INPUT @001 DMIS_ID $4.
@001 DMIS_ID_2 $4. /* added 9-16-08 by hjohnson */
@005 DEERS_FAM_ID $9.
@014 DEERS_BEN_ID $2.
@016 PTNT_ID $10.
@026 PTNT_LST_NM $27.
@053 PTNT_FST_NM $20.
@073 SPSR_SSN $9.
@082 UNIQ_PTNT_REF_NBR $12.
@094 ENCTR_SETTING_CD $1.
@095 DIAG_1 $7.
@102 DIAG_2 $7.
@109 DIAG_3 $7.
@116 DIAG_4 $7.
@123 DIAG_5 $7.
@130 DIAG_6 $7.
@137 DIAG_7 $7.
@144 DIAG_8 $7.
@151 DIAG_9 $7.
@158 DIAG_10 $7.
@165 DIAG_11 $7.
@172 DIAG_12 $7.
@179 UNIQ_PROV_ID $18.
@ ;
if ENCTR_SETTING_CD in ('I','O') then do ;
input @197 MAJ_SPCL_CD $2. @ ;
end ;
else do ;
input @197 INST_TYP_CD $2. @ ;
end ;
output ENCTR_SETTING_CD;

INPUT @199 ORDR_UNIQ_PROV_ID $18.
@217 COST_char $11.
@217 COST 11.2
@228 COPAY_char $6.
@228 COPAY 6.2
@234 EMRG_FLG_IND $1.
@235 REL_ADMIS_DT_char $8. @ ;
if REL_ADMIS_DT_char in ('00000000',' ') then REL_ADMIS_DT = '31dec9999'd ;
else do ;
input @235 REL_ADMIS_DT yymmdd8. @ ;
end ;
output REL_ADMIS_DT;

INPUT @243 REL_DISP_DT_char $8. @ ;
if REL_DISP_DT_char in ('00000000',' ') then REL_DISP_DT = '31dec9999'd ;
else do ;
input @243 REL_DISP_DT yymmdd8. @ ;
end ;
output REL_DISP_DT;

INPUT @251 NBR_OF_SRVCS $1.
@252 SRVC_1_START_DT yymmdd8.
@260 SRVC_1_END_DT yymmdd8.
@268 SRVC_1_PL_OF_SRVC $2.
@270 SRVC_1_PROC_CD $7.
@283 SRVC_1_REL_DIAG_CD $7.
@290 SRVC_1_QTY $3.
@293 SRVC_2_START_DT yymmdd8.
@301 SRVC_2_END_DT yymmdd8.
@309 SRVC_2_PL_OF_SRVC $2.
@311 SRVC_2_PROC_CD $7.
@324 SRVC_2_REL_DIAG_CD $7.
@331 SRVC_2_QTY $3.
@334 SRVC_3_START_DT yymmdd8.
@342 SRVC_3_END_DT yymmdd8.
@350 SRVC_3_PL_OF_SRVC $2.
@352 SRVC_3_PROC_CD $7.
@365 SRVC_3_REL_DIAG_CD $7.
@372 SRVC_3_QTY $3.
@375 SRVC_4_START_DT yymmdd8.
@383 SRVC_4_END_DT yymmdd8.
@391 SRVC_4_PL_OF_SRVC $2.
@393 SRVC_4_PROC_CD $7.
@406 SRVC_4_REL_DIAG_CD $7.
@413 SRVC_4_QTY $3.
@416 SRVC_5_START_DT yymmdd8.
@424 SRVC_5_END_DT yymmdd8.
@432 SRVC_5_PL_OF_SRVC $2.
@434 SRVC_5_PROC_CD $7.
@447 SRVC_5_REL_DIAG_CD $7.
@454 SRVC_5_QTY $3.
@457 SRVC_6_START_DT yymmdd8.
@465 SRVC_6_END_DT yymmdd8.
@473 SRVC_6_PL_OF_SRVC $2.
@475 SRVC_6_PROC_CD $7.
@488 SRVC_6_REL_DIAG_CD $7.
@495 SRVC_6_QTY $3. @ ;
INPUT @498 HOSP_SRV_ADMIS_DT_char $8. @ ;
if HOSP_SRV_ADMIS_DT_char in('00000000',' ') then HOSP_SRV_ADMIS_DT = '31dec9999'd ;
else do ;
input @498 HOSP_SRV_ADMIS_DT yymmdd8. @ ;
end ;
output HOSP_SRV_ADMIS_DT;

INPUT @506 HOSP_SRVC_ADMIS_TYP_CD $1.
@507 HOSP_SRVC_ADMIS_SRC_CD $1.
@508 HOSP_SRVC_DISP_STS_CD $2. @ ;
INPUT @510 HOSP_SRV_DISP_DT_char $8. @ ;
if HOSP_SRV_DISP_DT_char in('00000000',' ') then HOSP_SRV_DISP_DT = '31dec9999'd ;
else do ;
input @510 HOSP_SRV_DISP_DT yymmdd8. @ ;
end ;
output HOSP_SRV_DISP_DT;

INPUT @518 ORIG_DRG_CD $3.
@521 HOSP_SRV_PROC_1 $7.
@528 HOSP_SRV_PROC_2 $7.
@535 HOSP_SRV_PROC_3 $7.
@542 HOSP_SRV_PROC_4 $7.
@549 HOSP_SRV_PROC_5 $7.
@556 HOSP_SRV_PROC_6 $7.
@563 POINT_OF_SERVICE $1.
@564 TRANS_TYP_CD $1.
;

if DMIS_ID = ' ' and DEERS_FAM_ID = ' ' and DEERS_BEN_ID = ' ' and PTNT_ID = ' ' and SPSR_SSN = ' ' then delete;

if DMIS_ID in ('0196','0197') then DMIS_ID = '0192'; /* added 9-16-08 by hjohnson */

if cost = . then cost = 0.0 ;
if copay = . then copay = 0.0 ;

if ENCTR_SETTING_CD = 'H' and HOSP_SRV_ADMIS_DT = '31dec9999'd then HOSP_SRV_ADMIS_DT = .;
if ENCTR_SETTING_CD = 'H' and HOSP_SRV_DISP_DT = '31dec9999'd then HOSP_SRV_DISP_DT = .;

if notdigit(ORIG_DRG_CD) = 0 then DRG_CD = left(input(ORIG_DRG_CD,8.)) ;
else DRG_CD = left(ORIG_DRG_CD) ;

ENCTR_TYP_CD = "&enctr_typ_cd." ;
output ENCTR_TYP_CD ;

if eof then do ;
call symput ('end_encounterid',sbmt_rec_idx_nbr) ;
end ;
run;

 

6 REPLIES 6
PaigeMiller
Diamond | Level 26

Where are these six file names stored? Are they in a text file, an Excel file, or does the program have to read the names of the file from some operating system function (if so, what operating system)?

--
Paige Miller
mauri0623
Quartz | Level 8

The files are located on a path called /saswrk0/scp/inbox and they are .DAT files.

Reeza
Super User
Is it only those files to be read in that folder or are there other DAT files? If those are the only files in that folder, change your filename to use a wildcard and it will read all at once.
mauri0623
Quartz | Level 8

Linux.

PaigeMiller
Diamond | Level 26

There are plenty of examples here in SAS communities of a macro, or other code, that will read the names of files from a directory/folder, and then once you have that, you can loop through each name found and perform your task on each file. I have never written one for Linux, so I'll pass, but I suspect it involves the dreaded DREAD function. https://documentation.sas.com/?cdcId=pgmmvacdc&cdcVersion=9.4&docsetId=lefunctionsref&docsetTarget=n...

--
Paige Miller
Astounding
PROC Star

If you want six SAS data sets, you can't name them all MCD.  Would it be acceptable to name the SAS data sets:

 

MCD190

MCD191

MCD192

MCD193

MCD194

MCD198

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 6 replies
  • 1047 views
  • 1 like
  • 4 in conversation