BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
alepage
Barite | Level 11
Yes you are right, that will do the same
alepage
Barite | Level 11

for Mr. Miller here's my complete script

 

data paths;
     length path $200;
     input path $;
     datalines;
/dwh_actuariat/sasprocess/prodmens/HYFIprep/output
/dwh_actuariat/sasprocess/prodmens/HYFIp/output
;
run;

/************************************************************/

%macro readfile(path,fname,suffix);
    DATA &fname.;
        INFILE "&path./&fname..&suffix";
        INPUT Cie $ 1
              province $ 2-3
              branch   $ 4-7
              priorcur $ 8
               polsrc  $ 9
               mois    $ 10-15
               lob     $ 16-23
               Trans   $ 24-26
               WP       27-41
               EP       42-56
               EU       57-71
               WU       72-86
               POLCNT   87-102
               POLEARN  103-117
               UW_CIE   $ 118
               DIST_CIE  $ 119
               OB_IND    $ 120-124
               BROKER_GROUP_IND $ 125-126
               GCNA_BRANCH      $ 127-128               
               POLICY_CATEGORY  $ 129
               NETWORK_PROVIDER $ 130-134
               AFFINITY_IND     $ 135
;
    RUN;
%mend readfile;
/*******************************************************/
%macro readtxtfile;
%let yearmin=2024;
%let yearmax=2025;
%let prefix=HyFIPrems;
%let suffix=txt;
%let path=/dwh_actuariat/sasprocess/prodmens/HYFIprep/output;

%do year = &yearmin %to &yearmax;
     %if &year. ne &yearmax. %then %let maxmonth=12; 
     %else %let maxmonth=7;
     %do month =01 %to &maxmonth.;
     %let formatted_month = %sysfunc(putn(&month, Z2.));
     %let fname=&prefix.&year.&formatted_month.;
          %put &fname..&suffix.;
          %readfile(&path,&fname,&suffix);

          PROC APPEND BASE=&prefix. DATA=&fname.;
          RUN;
     %end;
%end;

%mend readtxtfile;
/******************************************/
*%readtxtfile;

%macro readtxtfile2(path);
%let yearmin=2025;
%let yearmax=2025;
%let minmonth=1;
%let maxmonth=7;

%let prefix=HyFIPrems;
%let suffix=txt;


%do year = &yearmin %to &yearmax;     
     %do month =&minmonth. %to &maxmonth.;
     %let formatted_month = %sysfunc(putn(&month, Z2.));
     %let fname=&prefix.&year.&formatted_month.;
          %put &fname..&suffix.;
          
          %readfile(&path,&fname,&suffix);

          %let substring=prep;


          %if %sysfunc(find(&path. , &substring.)) > 0 %then 
          %do;
               PROC APPEND BASE=&prefix. DATA=&fname.;
               RUN;
          %end;
          %else
          %do;
               PROC APPEND BASE=&prefix._org DATA=&fname.;
               RUN;
          %end; 


          
     %end;
%end;

%mend readtxtfile2;
%macro process;
proc sql noprint;
     select path into :path_list separated by ' '
     from paths;
quit;

%put &=path_list;


%let i = 1;
%do %while (%qscan(&path_list, &i. ,%str( )) ne );
     %let current_path = %scan(&path_list, &i. , %str( ));
     %put &=current_path;
     %readtxtfile2(&current_path);

     %let i = %eval(&i. + 1);
%end;


%mend process;
%process;
Tom
Super User Tom
Super User

Macro programming is fun, but don't use it when it is not needed.

Looks to me like you want to run this data step to create your two output datasets.

data paths;
  infile datalines truncover;
  input path $200.;
datalines;
/dwh_actuariat/sasprocess/prodmens/HYFIprep/output
/dwh_actuariat/sasprocess/prodmens/HYFIp/output
;

%let prefix=HyFIPrems;
%let substring=prep;

data &prefix. &prefix._org ;
  set paths;
  do year=2025 to 2025 ;
    do month = 1 to 7 ;
      length fname $256 ;
      fname=catx('/',path,cats("&prefix",year,put(month,z2.),'.txt'));
      infile text filevar=fname truncover end=eof; 
      do while(not eof);
        INPUT Cie $ 1
              province $ 2-3
              branch   $ 4-7
              priorcur $ 8
              polsrc  $ 9
              mois    $ 10-15
              lob     $ 16-23
              Trans   $ 24-26
              WP       27-41
              EP       42-56
              EU       57-71
              WU       72-86
              POLCNT   87-102
              POLEARN  103-117
              UW_CIE   $ 118
              DIST_CIE  $ 119
              OB_IND    $ 120-124
              BROKER_GROUP_IND $ 125-126
              GCNA_BRANCH      $ 127-128               
              POLICY_CATEGORY  $ 129
              NETWORK_PROVIDER $ 130-134
              AFFINITY_IND     $ 135
        ;
        if find(path,"&substring") then output  &prefix.;
        else output &prefix._org ;
      end;
    end;
  end;
run;

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 17 replies
  • 1068 views
  • 12 likes
  • 7 in conversation