Search code examples
sastext-filesenterprise-guide

SAS adding unwanted spaces to file names when macro variables are included


I'm creating a text file with SAS and I'm using a macro variable with a date in my text file's name to make it distinct from other similar files.

The problem I'm experiencing:

SAS is adding two unwanted spaces in the middle of the file name. The unwanted spaces are placed directly before the text generated by my macro variable

I'm certain this has everything to do with my macro variable being used, but on its own, the variable doesn't contain any spaces. Below is my code:

proc format;
    picture dateFormat
    other = '%Y%0m%0d%0H%0M' (datatype=datetime);
run;

data _null_;
    dateTime=datetime();
    call symput('dateTime', put(dateTime,dateFormat.));
run;

%LET FILE = text_text_abc_&dateTime..txt;

filename out "/location/here/&FILE" termstr=crlf;

data _null_; set flatfile;
    /*file content is created in here*/
run;

The exported file name will look like this:

NOTE: The file OUT is:
    Filename=/location/here/text_text_abc_  201702010855.txt

If it helps, I'm using SAS E-Guide 7.1.

Any help is appreciated! Thanks, all!


Solution

  • You need to assign an appropriate default length to your picture format. SAS is applying a default default length of 14 but you need 12, e.g.

    proc format;
        picture dateFormat (default=12)
        other = '%Y%0m%0d%0H%0M' (datatype=datetime);
    run;