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

I tried to rename the dataset using proc datasets.  SAS didn't recognize 3 datasets amount 8.  It seems SAS cannot read long dataset's names.  Is there way to way around this problem?  Thank you so much for your help.

 

292  %macro readdata(memname,name);
293  filename datafile "e:\Users\mhollifi\Desktop\Jotikasthira\USA_FO_Active_2016-04\&memname" ;
294  filename mapfile
294! "e:\Users\mhollifi\Desktop\Jotikasthira\USA_FO_Active_2016-04\5-2016-04-30.map" ;
295
296  libname datafile xmlv2 xmlmap=mapfile automap=replace;
297  proc datasets lib = datafile;
298  change Country = country&name
299         Currency = currency&name
300         Holding = holding&name
301         Holdingaggregate  = Holdingaggregate&name
302         Holdingdetail = Holdingdetail&name
303         Portfolio = Portfolio&name
304         Portfoliosummary = Portfoliosummary&name;
305
306  proc copy in=datafile out=work;
307  run;
308  %mend;
309
310  data _null_;
311  set contents(obs = 1);
312  period = findc(memname,'-'); put period =;
313  name = substr(memname,1,period-1); put name =;
314
315  call execute('%nrstr(%readdata(' || memname || ', ' || name || '))' ) ;
316  run;

period=8
name=1000165
NOTE: There were 1 observations read from the data set WORK.CONTENTS.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.00 seconds


NOTE: CALL EXECUTE generated line.
1   + %readdata(1000165-2016-04-30.xml

                        , 1000165
2   +
                                                                   )
MPRINT(READDATA):   filename datafile
"e:\Users\mhollifi\Desktop\Jotikasthira\USA_FO_Active_2016-04\1000165-2016-04-30.xml" ;
MPRINT(READDATA):   filename mapfile
"e:\Users\mhollifi\Desktop\Jotikasthira\USA_FO_Active_2016-04\5-2016-04-30.map" ;
MPRINT(READDATA):   libname datafile xmlv2 xmlmap=mapfile automap=replace;
NOTE: Processing XMLMap version 2.1.
NOTE: Libref DATAFILE was successfully assigned as follows:
      Engine:        XMLV2
      Physical Name:
      e:\Users\mhollifi\Desktop\Jotikasthira\USA_FO_Active_2016-04\1000165-2016-04-30.xml
MPRINT(READDATA):   proc datasets lib = datafile;
MPRINT(READDATA):   change Country = country1000165 Currency = currency1000165 Holding =
holding1000165 Holdingaggregate = Holdingaggregate1000165 Holdingdetail = Holdingdetail1000165
Portfolio = Portfolio1000165 Portfoliosummary = Portfoliosummary1000165;

ERROR: The file DATAFILE.Holdingaggregate (memtype=ALL) was not found, but appears on a CHANGE
       statement.
ERROR: The file DATAFILE.Holdingdetail (memtype=ALL) was not found, but appears on a CHANGE
       statement.
ERROR: The file DATAFILE.Portfoliosummary (memtype=ALL) was not found, but appears on a CHANGE
       statement.
NOTE: Statements not processed because of errors noted above.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE DATASETS used (Total process time):
      real time           0.05 seconds
      cpu time            0.01 seconds

 

MPRINT(READDATA):   proc copy in=datafile out=work;
MPRINT(READDATA):   run;

NOTE: Copying DATAFILE.Country to WORK.COUNTRY (memtype=DATA).
NOTE: BUFSIZE is not cloned when copying across different engines.
      System Option for BUFSIZE was used.
NOTE: There were 81 observations read from the data set DATAFILE.Country.
NOTE: The data set WORK.COUNTRY has 81 observations and 4 variables.
NOTE: Copying DATAFILE.Currency to WORK.CURRENCY (memtype=DATA).
NOTE: BUFSIZE is not cloned when copying across different engines.
      System Option for BUFSIZE was used.
NOTE: There were 81 observations read from the data set DATAFILE.Currency.
NOTE: The data set WORK.CURRENCY has 81 observations and 4 variables.
NOTE: Copying DATAFILE.Holding to WORK.HOLDING (memtype=DATA).
NOTE: BUFSIZE is not cloned when copying across different engines.
      System Option for BUFSIZE was used.
NOTE: There were 1 observations read from the data set DATAFILE.Holding.
NOTE: The data set WORK.HOLDING has 1 observations and 2 variables.
NOTE: Copying DATAFILE.HoldingAggregate to WORK.HOLDINGAGGREGATE (memtype=DATA).
NOTE: BUFSIZE is not cloned when copying across different engines.
      System Option for BUFSIZE was used.
NOTE: There were 1 observations read from the data set DATAFILE.HoldingAggregate.
NOTE: The data set WORK.HOLDINGAGGREGATE has 1 observations and 7 variables.
NOTE: Copying DATAFILE.HoldingDetail to WORK.HOLDINGDETAIL (memtype=DATA).
NOTE: BUFSIZE is not cloned when copying across different engines.
      System Option for BUFSIZE was used.
NOTE: There were 117 observations read from the data set DATAFILE.HoldingDetail.
NOTE: The data set WORK.HOLDINGDETAIL has 117 observations and 27 variables.
NOTE: Copying DATAFILE.Portfolio to WORK.PORTFOLIO (memtype=DATA).
NOTE: BUFSIZE is not cloned when copying across different engines.
      System Option for BUFSIZE was used.
NOTE: There were 1 observations read from the data set DATAFILE.Portfolio.
NOTE: The data set WORK.PORTFOLIO has 1 observations and 3 variables.
NOTE: Copying DATAFILE.PortfolioSummary to WORK.PORTFOLIOSUMMARY (memtype=DATA).
NOTE: BUFSIZE is not cloned when copying across different engines.
      System Option for BUFSIZE was used.
NOTE: There were 1 observations read from the data set DATAFILE.PortfolioSummary.
NOTE: The data set WORK.PORTFOLIOSUMMARY has 1 observations and 4 variables.
NOTE: PROCEDURE COPY used (Total process time):
      real time           0.06 seconds
      cpu time            0.04 seconds

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

I am not sure that Proc Datasets is intended to change XML in place. Datasets typically operates on the file information stored in a SAS data set and that does not exist in an xml file.

You might try 1)copying the data sets from the XML document to another library, 2) running the Datasets code on those sets and 3) writing back to the xml.

View solution in original post

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

A SAS data set can be 32 characters max.

 

Make sure that Holdingaggregate, Holdingdetail and Portfoliosummary  exist in the datafile library 🙂

Astounding
PROC Star

Very rarely, SAS code respects the case used when referring to SAS data sets.  It looks like this is one of those rare cases.

 

Within your CHANGE statement, you refer to these data sets:

 

Holdingaggregate

Holdingdetail

Portfoliosummary

 

However, the PROC COPY results indicate that these names should actually be:

 

HoldingAggregate

HoldingDetail

PortfolioSummary

 

Change the capitalization within the CHANGE statement, and that should handle the problem.  Recommended to avoid future issues:

 

HoldingAggregate = holdingaggregate&name

ballardw
Super User

I am not sure that Proc Datasets is intended to change XML in place. Datasets typically operates on the file information stored in a SAS data set and that does not exist in an xml file.

You might try 1)copying the data sets from the XML document to another library, 2) running the Datasets code on those sets and 3) writing back to the xml.

mhollifi
Obsidian | Level 7

The case of name worked but now has different problem...

 

17   options mprint;
18   %macro readdata(memname,name);
19   filename datafile "e:\Users\mhollifi\Desktop\Jotikasthira\USA_FO_Active_2016-04\&memname" ;
20   filename mapfile
20 ! "e:\Users\mhollifi\Desktop\Jotikasthira\USA_FO_Active_2016-04\5-2016-04-30.map" ;
21
22   libname datafile xmlv2 xmlmap=mapfile automap=replace;
23   proc datasets lib = datafile;
24   change Country = country&name
25          Currency = currency&name
26          Holding = holding&name
27          HoldingAggregate  = HoldingAggregate&name
28          HoldingDetail = HoldingDetail&name
29          Portfolio = Portfolio&name
30          PortfolioSummary = PortfolioSummary&name;
31
32   proc copy in=datafile out=work;
33   run;
34   %mend;
35
36   data _null_;
37   set contents(obs = 2);
38   period = findc(memname,'-'); put period =;
39   name = substr(memname,1,period-1); put name =;
40
41   call execute('%nrstr(%readdata(' || memname || ', ' || name || '))' ) ;
42   run;

period=8
name=1000165
period=8
name=1000166
NOTE: There were 2 observations read from the data set WORK.CONTENTS.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


NOTE: CALL EXECUTE generated line.
1   + %readdata(1000165-2016-04-30.xml

                        , 1000165
2   +
                                                                   )
MPRINT(READDATA):   filename datafile
"e:\Users\mhollifi\Desktop\Jotikasthira\USA_FO_Active_2016-04\1000165-2016-04-30.xml" ;
MPRINT(READDATA):   filename mapfile
"e:\Users\mhollifi\Desktop\Jotikasthira\USA_FO_Active_2016-04\5-2016-04-30.map" ;
MPRINT(READDATA):   libname datafile xmlv2 xmlmap=mapfile automap=replace;
NOTE: Processing XMLMap version 2.1.
NOTE: Libref DATAFILE was successfully assigned as follows:
      Engine:        XMLV2
      Physical Name:
      e:\Users\mhollifi\Desktop\Jotikasthira\USA_FO_Active_2016-04\1000165-2016-04-30.xml
NOTE: Writing HTML Body file: sashtml.htm
MPRINT(READDATA):   proc datasets lib = datafile;
MPRINT(READDATA):   change Country = country1000165 Currency = currency1000165 Holding =
holding1000165 HoldingAggregate = HoldingAggregate1000165 HoldingDetail = HoldingDetail1000165
Portfolio = Portfolio1000165 PortfolioSummary = PortfolioSummary1000165;

NOTE: Changing the name DATAFILE.Country to DATAFILE.country1000165 (memtype=DATA).
ERROR: The FILE RENAME function is not supported by the XMLV2 engine.
NOTE: Changing the name DATAFILE.Currency to DATAFILE.currency1000165 (memtype=DATA).
ERROR: The FILE RENAME function is not supported by the XMLV2 engine.
NOTE: Changing the name DATAFILE.Holding to DATAFILE.holding1000165 (memtype=DATA).
ERROR: The FILE RENAME function is not supported by the XMLV2 engine.
NOTE: Changing the name DATAFILE.HoldingAggregate to DATAFILE.HoldingAggregate1000165
      (memtype=DATA).
ERROR: The FILE RENAME function is not supported by the XMLV2 engine.
NOTE: Changing the name DATAFILE.HoldingDetail to DATAFILE.HoldingDetail1000165 (memtype=DATA).
ERROR: The FILE RENAME function is not supported by the XMLV2 engine.
NOTE: Changing the name DATAFILE.Portfolio to DATAFILE.Portfolio1000165 (memtype=DATA).
ERROR: The FILE RENAME function is not supported by the XMLV2 engine.
NOTE: Changing the name DATAFILE.PortfolioSummary to DATAFILE.PortfolioSummary1000165
      (memtype=DATA).
ERROR: The FILE RENAME function is not supported by the XMLV2 engine.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE DATASETS used (Total process time):
      real time           0.28 seconds
      cpu time            0.20 seconds

 

MPRINT(READDATA):   proc copy in=datafile out=work;
MPRINT(READDATA):   run;

NOTE: Copying DATAFILE.Country to WORK.COUNTRY (memtype=DATA).
NOTE: BUFSIZE is not cloned when copying across different engines.
      System Option for BUFSIZE was used.
NOTE: There were 81 observations read from the data set DATAFILE.Country.
NOTE: The data set WORK.COUNTRY has 81 observations and 4 variables.
NOTE: Copying DATAFILE.Currency to WORK.CURRENCY (memtype=DATA).
NOTE: BUFSIZE is not cloned when copying across different engines.
      System Option for BUFSIZE was used.
NOTE: There were 81 observations read from the data set DATAFILE.Currency.
NOTE: The data set WORK.CURRENCY has 81 observations and 4 variables.
NOTE: Copying DATAFILE.Holding to WORK.HOLDING (memtype=DATA).
NOTE: BUFSIZE is not cloned when copying across different engines.
      System Option for BUFSIZE was used.
NOTE: There were 1 observations read from the data set DATAFILE.Holding.
NOTE: The data set WORK.HOLDING has 1 observations and 2 variables.
NOTE: Copying DATAFILE.HoldingAggregate to WORK.HOLDINGAGGREGATE (memtype=DATA).
NOTE: BUFSIZE is not cloned when copying across different engines.
      System Option for BUFSIZE was used.
NOTE: There were 1 observations read from the data set DATAFILE.HoldingAggregate.
NOTE: The data set WORK.HOLDINGAGGREGATE has 1 observations and 7 variables.
NOTE: Copying DATAFILE.HoldingDetail to WORK.HOLDINGDETAIL (memtype=DATA).
NOTE: BUFSIZE is not cloned when copying across different engines.
      System Option for BUFSIZE was used.
NOTE: There were 117 observations read from the data set DATAFILE.HoldingDetail.
NOTE: The data set WORK.HOLDINGDETAIL has 117 observations and 27 variables.
NOTE: Copying DATAFILE.Portfolio to WORK.PORTFOLIO (memtype=DATA).
NOTE: BUFSIZE is not cloned when copying across different engines.
      System Option for BUFSIZE was used.
NOTE: There were 1 observations read from the data set DATAFILE.Portfolio.
NOTE: The data set WORK.PORTFOLIO has 1 observations and 3 variables.
NOTE: Copying DATAFILE.PortfolioSummary to WORK.PORTFOLIOSUMMARY (memtype=DATA).
NOTE: BUFSIZE is not cloned when copying across different engines.
      System Option for BUFSIZE was used.
NOTE: There were 1 observations read from the data set DATAFILE.PortfolioSummary.
NOTE: The data set WORK.PORTFOLIOSUMMARY has 1 observations and 4 variables.
NOTE: PROCEDURE COPY used (Total process time):
      real time           0.07 seconds
      cpu time            0.06 seconds

mhollifi
Obsidian | Level 7
It's not xml file anymore. I changed it to sas dataset. I have 4 thousand datasets with same name, so I need to change the name of each datasets if not it's just over write it.
mhollifi
Obsidian | Level 7
thank you I finally understand what you mean. it worked.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 6 replies
  • 2758 views
  • 0 likes
  • 4 in conversation