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

Hello, teachers, use the SAS official website %loc2xpt to convert the SAS data set into XPT format. If there is  ae and ya in the logic library, two data sets will be converted into an XPT file at the same time. I read the next%loc2xpt program.Can't there be a data set starting with y with% loc2xpt?

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

For more minimalist change change the Y used by the format to lowercase.

Then you just have to change one letter each in two files.

In xptcommn.sas change set label to lowercase y instead of Y.

%macro make_memwant_fmt(memlist);
%global singmem;
data cntlin;
     fmtname='$memwant'; label='y'; hlo=' ';

In loc2xpt.sas change the Y to lowercase also

        want = memtype='DATA' and put(upcase(memname),$memwant.)='y';

You can see that the %LOC2XPT macro is passing the uppercase version of the member name to the $MEMWANT format. So even though the format is not fixed to include an other case so it will still return the first letter of unmatched names that letter can never by lowercase here because of the UPCASE() function call.

View solution in original post

12 REPLIES 12
JosvanderVelden
SAS Super FREQ
I assume you have seen the documentation https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/movefile/p13q0v60f08mj3n1ebm8salcpkmh.htm. What exactly is the issue for you?
Taking the code below if you have datasets ae and ya in yourlib then you will get ae and ya in work. Or does that not work for you?
%loc2xpt(libref=yourlib,
filespec='yourtransportfile.v9xpt' )
%xpt2loc(libref=work,
filespec='yourtransportfile.v9xpt' )
ballardw
Super User

Please read the text you posted carefully and confirm that "ae" and "ya" are indeed to two ASCII characters and not some single character such as "æ".

If special characters you would have to make sure that option Validmemname=Extend is set and use name literals, the data set name in quotes followed by n such as "æ_otherbits"n to reference the data set name(s).

Tom
Super User Tom
Super User

What is the question exactly?
If if ask %LOC2XPT() to put more than one dataset into the same XPORT file it will do that.

whymath
Lapis Lazuli | Level 10

I remember one of my colleagues has met this bug.

 

The bug is from a sub macro of %loc2xpt, named %make_memwant_fmt, you can find it in xptcommn.sas, at path %sysget(sasroot)\core\sasmacro.

Now open this file in your SAS editor, the 'Y' letter is from the 3rd line of %make_memwant_fmt.

OrangePeel
Fluorite | Level 6
yes,thanks,How to solve it?
whymath
Lapis Lazuli | Level 10

I'm sorry I can not do a test for you now. I would suggest you to start at deleting the format dataset at each time you call this macro. 

Tom
Super User Tom
Super User

The issue is that the format generated does not include and OTHER clause so instead of returning NO or some other fixed text when the member is not in the desired list it returns the first letter of the name.  Since LOC2XPT is testing if the formatted value is Y then any dataset whose name starts with an uppercase Y will be included.

 

I reported the issue to SAS Support so hopefully eventually they will fix it.

 

In the meantime make a copy of the LOC2XPT macro and make the following change.

Replace this line:

        want = memtype='DATA' and put(upcase(memname),$memwant.)='Y';

With this block of code instead:

%if 0=%length(&memlist) or  %qupcase(&memlist) = _ALL_ %then %do;
        want = memtype='DATA';
%end;
%else %do;
  %local i member ;
        want = memtype='DATA' and upcase(memname) in (
  %do i=1 %to %sysfunc(countw(&memlist,%str( ),q));
     %let member=%qscan(&memlist,&i,%str( ),q);
     %let member=%qupcase(%qsysfunc(dequote(&member)));
     %let member=%sysfunc(quote(&member,%str(%')));
        &member
   %end;
        );
%end;

So basically it skips the FORMAT altogether and just generates an IN condition when you give a list of names. The names can by quoted to allow for non-standard names supported when VALIDMEMNAME=EXTEND setting is in place.

Tom
Super User Tom
Super User

For more minimalist change change the Y used by the format to lowercase.

Then you just have to change one letter each in two files.

In xptcommn.sas change set label to lowercase y instead of Y.

%macro make_memwant_fmt(memlist);
%global singmem;
data cntlin;
     fmtname='$memwant'; label='y'; hlo=' ';

In loc2xpt.sas change the Y to lowercase also

        want = memtype='DATA' and put(upcase(memname),$memwant.)='y';

You can see that the %LOC2XPT macro is passing the uppercase version of the member name to the $MEMWANT format. So even though the format is not fixed to include an other case so it will still return the first letter of unmatched names that letter can never by lowercase here because of the UPCASE() function call.

whymath
Lapis Lazuli | Level 10
Very impressive!
OrangePeel
Fluorite | Level 6
Yes, this modification works, but it also needs to be modified like this when using %xpt2loc
Tom
Super User Tom
Super User

@OrangePeel wrote:
Yes, this modification works, but it also needs to be modified like this when using %xpt2loc

If XPT2LOC is using the same logic to restrict the members to export then it probably has the same bug.  Looks like it is line #373.

image.png

Tom
Super User Tom
Super User

Looks like this particular bug is fixed in SAS 9.4 M7 release.

 

The macro still has trouble with non-standard member names. 

7    %xptcommn;

MAUTOCOMPLOC:  The autocall macro SETDCB is compiling using the autocall source file

            /Volumes/app/sas/devel/sas9.4_m7/SASFoundation/9.4/sasautos/xptcommn.sas.

MPRINT(XPTCOMMN):   * just need to define this to avoid a warning message;

8    options mprint;

9    %make_memwant_fmt(abc '1234');

 

 

MPRINT(MAKE_MEMWANT_FMT):   data cntlin;

MPRINT(MAKE_MEMWANT_FMT):   fmtname='$memwant';

MPRINT(MAKE_MEMWANT_FMT):   label='Y';

MPRINT(MAKE_MEMWANT_FMT):   hlo=' ';

MPRINT(MAKE_MEMWANT_FMT):   length start $32;

MPRINT(MAKE_MEMWANT_FMT):   start=' ';

MAUTOCOMPLOC:  The autocall macro TRIM is compiling using the autocall source file

            /Volumes/app/sas/devel/sas9.4_m7/SASFoundation/9.4/sasautos/trim.sas.

MPRINT(MAKE_MEMWANT_FMT):   start=upcase(left("abc "));

MPRINT(MAKE_MEMWANT_FMT):   output;

NOTE: One or more missing close parentheses have been supplied for the %LENGTH function.

ERROR: The macro MAKE_MEMWANT_FMT will stop executing.

 

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.CNTLIN may be incomplete.  When this step was stopped there were 0

         observations and 4 variables.

NOTE: DATA statement used (Total process time):

      real time           0.01 seconds

      cpu time            0.01 seconds

 

But those are much less common than non standard variable names.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 12 replies
  • 2973 views
  • 3 likes
  • 5 in conversation