I am trying to access the files in a path and trying to convert into Macro. My macro variables are not resolving since the INFILE statement have both single and double quotes. I tried using Multiple double quotes, %bquote, or "%'". But not successful. If I use the the "Double quotes" before the 'Dir' then it throwing me error. How I can I convert this into Macro and resolve the Macro variables. The path is working without Converting to Macro. Thank you for your inputs.
options symbolgen mprint mlogic;
%let folder = document;
%let loc = Desktop;
data filenames_;
infile 'dir "D:\&loc.\&folder.\*" /B/S/A-D/ON' pipe truncover;
input path_file $1000.;
run;
Hello @SASuserlot,
First replace the single quotes by double quotes. For your example values of folder and doc you can just delete the inner (double) quotes. If you need them (potentially) for other values of the macro variables (e.g., folder names containing blanks), duplicate the inner double quotes:
infile "dir ""D:\&loc.\&folder.\*"" /B/S/A-D/ON" pipe truncover;
Hello @SASuserlot,
First replace the single quotes by double quotes. For your example values of folder and doc you can just delete the inner (double) quotes. If you need them (potentially) for other values of the macro variables (e.g., folder names containing blanks), duplicate the inner double quotes:
infile "dir ""D:\&loc.\&folder.\*"" /B/S/A-D/ON" pipe truncover;
Thank you , your solution made it😍. Is there any reference paper or link, that I can refer, I always have the trouble with these double and single quotes specially when both of them there.
@SASuserlot wrote:
Thank you , your solution made it😍. Is there any reference paper or link, that I can refer, I always have the trouble with these double and single quotes specially when both of them there.
They seem to have removed (or hidden in some hard to find place) the SAS Language documentation where this type of topic was discussed.
Here is the description in the on-line SAS 9.3 documentation.
Using Quotation Marks with Character Constants
In the following SAS statement, Tom is a character constant:
if name='Tom' then do;
If a character constant includes a single quotation mark, surround it with double quotation marks. For example, to specify the character value Tom's as a constant, enter
name="Tom's"
Another way to write the same string is to enclose the string in single quotation marks and to express the apostrophe as two consecutive quotation marks. SAS treats the two consecutive quotation marks as one quotation mark:
name='Tom''s'
The same principle holds true for double quotation marks:
name="Tom""s"
CAUTION:
Matching quotation marks correctly is important.
Missing or extraneous quotation marks cause SAS to misread both the erroneous statement and the statements that follow it. For example, in name='O'Brien';, O is the character value of NAME, Brien is extraneous, and '; begins another quoted string.
Thanks to @Tom for providing the documentation link during the European night. The corresponding documentation for SAS 9.4/Viya 3.5 is https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lrcon/p0cq7f0icfjr8vn19vyunwmmsl7m.htm. But, strangely enough, switching to the latest Viya version 2022.10 leads to a page saying "The page you were viewing is unavailable for the version you selected." Applying the recent "Pro-tip: How to view the latest SAS documentation" to the "9.4_3.5" part of the URL yields "Page Not Found".
Luckily, older documentation (at least back to SAS V8) and conference papers are still available online, a number of long-time SAS users in this forum remember what they learned using SAS V6 and earlier (which is how I recalled the double double-quote trick) and a few of them even own a copy of ancient printed documentation.
In your example the key was basically to combine the principle "avoid single quotes around macro variable references as they prevent their resolution" with the special meaning of duplicate quotes (of the same type) in certain places.
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.
Ready to level-up your skills? Choose your own adventure.