I have had some great help on this board and Chris helped me with finding the right path to connect to a shared drive and finding the zipped files. I have 12 folders that have multiple zipped files and I was coding each zipped file as I will show in my code and each .txt file I need from the zipped file. But there are over 200 .txt files in this one zipped folder and I only need the files that have the extension detail.txt. The other files I can disregard. They are flagged.txt. Here is an example of what I have as code now and just want to find an easier way than going back and forth to the shared drive and typing in all these lengthy names:
[code]
filename fromzip zip '\\agpcorp\files\va1\Private\managedcaresvcs\health-qualitymgmt\hedis rates_datasets_benchmarks\hedis 2017\datasets\2016_03_mar hedis 2017_my2016\me1\hedis2017_mar2016_md medicaidchip.zip';
data _null_;
length memname $256;
input memname $;
infile fromzip memvar=memname end=eof;
eof=0;
do while(not eof);
input;
put memname= _infile_;
end;
datalines;
%_rye_mbr_benefit_16_rider16_detail.txt;
adh_med_schizo_16_saa16_detail.txt;
adhere_antipsy_16_am_saa16am_detail.txt;
adol_well_care_16_ch_awc16ch_detail.txt;
adolesc_well_care_16_awc16_detail.txt;
adult_bmi_16_am_aba16am_detail.txt;
adult_bmi_assmt_16_aba16_detail.txt;
adult_access_16_aap16_detail.txt;
ambulatory_care_16_amb16_detail.txt;
ambulatory_care_16_ch_amb16ch_detail.txt;
annual_dental_16_adv16_detail.txt;
annual_mon_rx_16_am_mpm16am_detail.txt;
annual_monitor_rx_16_mpm16_detail.txt;
antemmedmgmntasthma16_mma16wl_detail.txt;
antenatal_stds_16_am_ans16am_detail.txt;
antibiotic_util_16_abx16_detail.txt;
antidepr_meds_16_am_amm16am_detail.txt;
antidepress_meds_16_amm16_detail.txt;
anitpsy_psychosoc_16_app16_detail.txt;
app_test_pharyng_16_cwp16_detail.txt;
app_treatment_uri_16_uri16_detail.txt;
asthma_admit_16_am_aar16am_detail.txt;
asthma_med_ratio_16_amr16_detail.txt;
avoid_abx_bronch_16_aab16_detail.txt;
behavior_risk_16_ch_bra16ch_detail.txt;
breast_cancer_16_am_bcs16am_detail.txt;
cahps_adult_survey_16_cpa16_detail.txt;
cahps_child_16_ch_cpc16ch_detail.txt;
cahps_child_survey_16_cpc16_detail.txt;
breast_cancer_16_bcs16_detail.txt;
cardio_schizo_16_smc_16_detail.txt;
care_trans_16_am_ctr16am_detail.txt;
cervical_c_scr_16_am_ccs16am_detail.txt;
chf_admit_16_am_chf16am_detail.txt;
child_access_16_ch_cap16ch_detail.txt;
child_imm_w_lead_16_cis16q_detail.txt;
childhood_imm_16_ch_cis16ch_detail.txt;
childhood_imm_16_cis16_detail.txt;
childrens_access_16_cap16_detail.txt;
chlamyd_screen_16_ch_chl16ch_detail.txt;
chlamydia_screen_16_chl16_detail.txt;
chlamydia_scrn_16_am_chl16am_detail.txt;
colorectal_cancer_16_col16_detail.txt;
comp_diabetes_16_cdc16_detail.txt;
control_hbp_16_am_cbp16am_detail.txt;
control_high_bp_16_cbp16_detail.txt;
copd_admit_16_am_cpr16am_detail.txt;
csr_for_ntsv_16_ch_csr16ch_detail.txt;
dental_sealant_16_ch_sea16ch_detail.txt;
dev_scrn_1_3_16_ch_dsv16ch_detail.txt;
dev_scrn_age_1_16_ch_dvs16cha_detail.txt;
dev_scrn_age_2_16_ch_dvs16chb_detail.txt;
dev_scrn_age_3_16_ch_dvs16chc_detail.txt;
diab_monit_schizo_16_smd16_detail.txt;
diab_screen_schiz_16_ssd16_detail.txt;
diabetes_a1c_16_am_cdc16am_detail.txt;
diabetes_admit_16_am_dsr16am_detail.txt;
diabetes_poor_16_am_hpc16am_detail.txt;
dmard_rheum_arthr_16_art16_detail.txt;
ed_utilization_16_edu16_detail.txt;
elec_delivery_16_am_edr16am_detail.txt;
fllwup_hosp_mh_16_ch_fuh16ch_detail.txt;
cervical_cancer_16_ccs16_detail.txt;
follow_up_hosp_mh_16_fuh16_detail.txt;
;
[\code]
Hi @tmcrouse, it seems like you might need a two-pass approach for this. First pass is to assemble the list of TXT files that you need to process, and then for each text file you find, generate a SAS program that does the work of reading in the data from it. You don't say whether all of the text files have the same format -- it would be good if they do, as that will make things much easier.
Code might look something like this...
filename fromzip zip 'c:\temp\class.zip';
data contents(keep=memname isFolder);
length memname $200 isFolder 8;
fid=dopen("fromzip");
if fid=0 then
stop;
memcount=dnum(fid);
do i=1 to memcount;
memname=dread(fid,i);
/* check for trailing / in folder name */
isFolder = (first(reverse(trim(memname)))='/');
output;
end;
rc=dclose(fid);
run;
options source2;
filename sasprog temp;
data _null_;
file sasprog;
length line $ 100;
set contents(keep=memname);
lines = 'data in; infile intxt(' || memname || '); input; put _infile_; run;';
put 'filename intxt ZIP "c:\temp\class.zip";' ;
put line;
put 'filename intxt clear;';
run;
%include sasprog;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.