BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Kayla_Tan222
Calcite | Level 5

 

 

Hi, i have a lot of files and i already  save them as the sas data set by using %macro.

I assigned a libref name polaclm in order to store all the sas data sets in the library.

However, i found that in my server library, only the last sas data set (the last file) is stored, the remaining sas data sets is not in the library.  But the thing is all the sas data sets are in my local pc(the path i save).

 

How can i solve this problem? i try to put %include beside libname polaclm but there was an error.

 

 is there anything wrong with my code?

 

 

/*Import POLA_clm_mth_201812*

**Folder:D:\POLA\2018\201812\CSV*/

%Macro POLA_clm_mth_(YYYY,YYYYMM);

libname polaclm "\\kaiwksgh415thw5\Data\POLA\&YYYY\&YYYYMM\DBF\";

Data polaclm.POLA_clm_mth_&YYYYMM.;

%let _EFIERR_=0;

 infile "\\kaiwksgh415thw5\Data\claims\POLA\source\POLA_clm_mth_&YYYYMM..csv" dlm=',' MISSOVER DSD lrecl=32767 firstobs=2;

informat rskcoy 1.;

informat zmajrsk $3.;

informat rsktyp $3.;

informat zbusnsrc 3.;

informat rskpfx $2.;

informat chdrnum $10.;

informat poltrnno 4.;

informat risktype $3.;

informat ccdate 8.;

informat crdate 8.;

informat rskno 3.;

informat dteeff 8.;

informat ztrnno 4.;

informat zsumsi 16.0;

informat clmpfx $2.;

informat clmcoy 1.;

informat claim $10.;

informat datocc 8.;

informat tranno 4.;

informat clntpfx $2.;

informat clntcoy 2.;

informat clntnum 10.;

informat acctyr 4.0;

informat acctmnth 2.0;

informat batctrcde $5.;

informat batcbrn $2.;

informat clstat 2.;

informat payflg $2.;

informat trndsc $30.;

informat reqnno $10.;

informat receipt $10.;

informat zclmos best16.2;

informat zclmpd best16.2;

informat zosqs best16.2;

informat zpdqs best16.2;

informat zosvc best16.2;

informat zpdvc best16.2;

informat zosaf best16.2;

informat zpdaf best16.2;

informat zossp01 best16.2;

informat zossp02 best16.2;

informat zossp03 best16.2;

informat zossp04 best16.2;

informat zossp05 best16.2;

informat zossp06 best16.2;

informat zpdsp01 best16.2;

informat zpdsp02 best16.2;

informat zpdsp03 best16.2;

informat zpdsp04 best16.2;

informat zpdsp05 best16.2;

informat zpdsp06 best16.2;

informat zosfac01 best16.2;

informat zosfac02 best16.2;

informat zpdfac01 best16.2;

informat zpdfac02 best16.2;

informat zosfri best16.2;

informat zpdfri best16.2;

informat zoscout best16.2;

informat zpdcout best16.2;

 

 

format rskcoy 1.;

format zmajrsk $3.;

format rsktyp $3.;

format zbusnsrc 3.;

format rskpfx $2.;

format chdrnum $10.;

format poltrnno 4.;

format risktype $3.;

format ccdate 8.;

format crdate 8.;

format rskno 3.;

format dteeff 8.;

format ztrnno 4.;

format zsumsi 16.0;

format clmpfx $2.;

format clmcoy 1.;

format claim $10.;

format datocc 8.;

format tranno 4.;

format clntpfx $2.;

format clntcoy 2.;

format clntnum 10.;

format acctyr 4.0;

format acctmnth 2.0;

format batctrcde $5.;

format batcbrn $2.;

format clstat 2.;

format payflg $2.;

format trndsc $30.;

format reqnno $10.;

format receipt $10.;

format zclmos best16.2;

format zclmpd best16.2;

format zosqs best16.2;

format zpdqs best16.2;

format zosvc best16.2;

format zpdvc best16.2;

format zosaf best16.2;

format zpdaf best16.2;

format zossp01 best16.2;

format zossp02 best16.2;

format zossp03 best16.2;

format zossp04 best16.2;

format zossp05 best16.2;

format zossp06 best16.2;

format zpdsp01 best16.2;

format zpdsp02 best16.2;

format zpdsp03 best16.2;

format zpdsp04 best16.2;

format zpdsp05 best16.2;

format zpdsp06 best16.2;

format zosfac01 best16.2;

format zosfac02 best16.2;

format zpdfac01 best16.2;

format zpdfac02 best16.2;

format zosfri best16.2;

format zpdfri best16.2;

format zoscout best16.2;

format zpdcout best16.2;

 

 

INPUT

rskcoy

zmajrsk $

rsktyp $

zbusnsrc

rskpfx $

chdrnum $

poltrnno

risktype $

ccdate

crdate

rskno

dteeff

ztrnno

zsumsi

clmpfx $

clmcoy

claim $

datocc

tranno

clntpfx $

clntcoy

clntnum

acctyr

acctmnth

batctrcde $

batcbrn $

clstat

payflg $

trndsc $

reqnno $

receipt $

zclmos

zclmpd

zosqs

zpdqs

zosvc

zpdvc

zosaf

zpdaf

zossp01

zossp02

zossp03

zossp04

zossp05

zossp06

zpdsp01

zpdsp02

zpdsp03

zpdsp04

zpdsp05

zpdsp06

zosfac01

zosfac02

zpdfac01

zpdfac02

zosfri

zpdfri

zoscout

zpdcout;

 

 if _ERROR_ then call symputx('_EFIERR_',1);

 

 

ccdate=input(put(ccdate,Z8.),yymmdd8.);

format ccdate yymmddn8.;

crdate=input(put(crdate,Z8.),yymmdd8.);

format crdate yymmddn8.;

dteeff=input(put(dteeff,Z8.),yymmdd8.);

format dteeff yymmddn8.;

datocc=input(put(datocc,Z8.),yymmdd8.);

format datocc yymmddn8.;

 

 

 

zclmosnet=sum(zclmos,-zosqs,-zosvc,-zosaf,-zossp01,-zossp02,-zossp03,-zossp04,-zossp05,-zossp06,-zosfac01,-zosfac02,-zosfri,-zoscout);

zclmpdnet=sum(zclmpd,-zpdqs,-zpdvc,-zpdaf,-zpdsp01,-zpdsp02,-zpdsp03,-zpdsp04,-zpdsp05,-zpdsp06,-zpdfac01,-zpdfac02,-zpdfri,-zpdcout);

 

 

if month(datocc)=12 then

lossyr_fy=year(datocc)+1;

 

else

lossyr_fy=year(datocc);

if acctmnth=12 and acctyr<=2014 then

accyr_fy=acctyr+1;

 

else

accyr_fy=acctyr;

if acctmnth=12 and acctyr<=2014 then

accmth_fy=1;

else if acctmnth^=12 and acctyr<=2014 then

accmth_fy=acctmnth+1;

 

else

accmth_fy=acctmnth;

dev7yr_fy=min(accyr_fy-lossyr_fy,7);

dev10yr_fy=min(accyr_fy-lossyr_fy,10);

 

run;

%mend Pola_clm_mth_;

%Pola_clm_mth_(2015,200612_201510);

%Pola_clm_mth_(2015,201511);

%Pola_clm_mth_(2015,201512);

%Pola_clm_mth_(2016,201601);

%Pola_clm_mth_(2016,201602);

%Pola_clm_mth_(2016,201603);

%Pola_clm_mth_(2016,201604);

%Pola_clm_mth_(2016,201605);

%Pola_clm_mth_(2016,201606);

%Pola_clm_mth_(2016,201607);

%Pola_clm_mth_(2016,201608);

%Pola_clm_mth_(2016,201609);

%Pola_clm_mth_(2016,201610);

%Pola_clm_mth_(2016,201611);

%Pola_clm_mth_(2016,201612);

%Pola_clm_mth_(2017,201701);

%Pola_clm_mth_(2017,201702);

%Pola_clm_mth_(2017,201703);

%Pola_clm_mth_(2017,201704);

%Pola_clm_mth_(2017,201705);

%Pola_clm_mth_(2017,201706);

%Pola_clm_mth_(2017,201707);

%Pola_clm_mth_(2017,201708);

%Pola_clm_mth_(2017,201709);

%Pola_clm_mth_(2017,201710);

%Pola_clm_mth_(2017,201711);

%Pola_clm_mth_(2017,201712);

%Pola_clm_mth_(2018,201801);

%Pola_clm_mth_(2018,201802);

%Pola_clm_mth_(2018,201803);

%Pola_clm_mth_(2018,201804);

%Pola_clm_mth_(2018,201805);

%Pola_clm_mth_(2018,201806);

%Pola_clm_mth_(2018,201807);

%Pola_clm_mth_(2018,201808);

%Pola_clm_mth_(2018,201809);

%Pola_clm_mth_(2018,201810);

%Pola_clm_mth_(2018,201811);

%Pola_clm_mth_(2018,201812);

RUN;

 

 

 

 

 

 

data polaclm.pola_clm_agg_201812;

set polaclm.pola_clm_mth_200612_201510

 

polaclm.pola_clm_mth_201511;

run;

 

 

 

 


 

 

1 ACCEPTED SOLUTION

Accepted Solutions
heffo
Pyrite | Level 9

It's because you change the folder where the libname is pointing to with every new file.

libname polaclm "\\kaiwksgh415thw5\Data\POLA\&YYYY\&YYYYMM\DBF\";

You actually don't need that for your program. You read the file from there, but that is in the infile statement. It would probably be better to have a fixed libname statement outside of your macro and save all the SAS tables to there. 

libname polaclm "\\kaiwksgh415thw5\Data\POLA\";

%Macro POLA_clm_mth_(YYYY,YYYYMM);
   Data polaclm.POLA_clm_mth_&YYYYMM.;
   <Your code... >
   run;
%mend Pola_clm_mth_;

%Pola_clm_mth_(2015,200612_201510);
... 

 

 

View solution in original post

3 REPLIES 3
heffo
Pyrite | Level 9

It's because you change the folder where the libname is pointing to with every new file.

libname polaclm "\\kaiwksgh415thw5\Data\POLA\&YYYY\&YYYYMM\DBF\";

You actually don't need that for your program. You read the file from there, but that is in the infile statement. It would probably be better to have a fixed libname statement outside of your macro and save all the SAS tables to there. 

libname polaclm "\\kaiwksgh415thw5\Data\POLA\";

%Macro POLA_clm_mth_(YYYY,YYYYMM);
   Data polaclm.POLA_clm_mth_&YYYYMM.;
   <Your code... >
   run;
%mend Pola_clm_mth_;

%Pola_clm_mth_(2015,200612_201510);
... 

 

 

Kayla_Tan222
Calcite | Level 5

Thanks heffo, you help me so much.

 

By the way if lets say I really want to save it at different new file , isit possible to do so?

heffo
Pyrite | Level 9

Sure, that is what you are doing now. But if you want to be able to see each library (could be many) then you need to change the libref for each library. 

libname p&YYYYMM "\\kaiwksgh415thw5\Data\POLA\&YYYY\&YYYYMM\DBF\";

Remember that your libref (the name of the library) can only be 8 characters long. And remember to now save the data set to 

Data p&YYYYMM..POLA_clm_mth_&YYYYMM.;

Notice that there are two dots! The first one is to tell SAS where the macro variable ends and the second one is to separate the library and the data set name. 

 

You could of course also save the files to a year folder then you will have: 

libname p&YYYY "\\kaiwksgh415thw5\Data\POLA\&YYYY\";

Data p&YYYY..POLA_clm_mth_&YYYYMM.;

Less libraries and less places where you save the data sets. 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 2183 views
  • 0 likes
  • 2 in conversation