Home > OS >  What is the difference between single and double qoutes in SAS and why does single quotes fail when
What is the difference between single and double qoutes in SAS and why does single quotes fail when

Time:09-15

What is the difference between single and double quotes in SAS, I have noticed they somtimes act different and somtimes simmilar. As an example I just discoverd using single quotes when importing csv files dosen't work.

This is the macro variable:

%Let Table_periode_MDR =\Afdeling\HS-OKO\Oko\Likviditet\Likviditetsstyring\LCR\Indberetning\2022\202208\RLI\Output_Daglig_LCR\MDR_korrektion.cs

This import didn't work:

proc import datafile= '&Table_periode_MDR'
        out=MDR_korrektion
        replace
        dbms=csv 
        replace;
        getnames=yes;
        delimiter=';';
run;

But this worked:

proc import datafile= "&Table_periode_MDR"
        out=MDR_korrektion
        replace
        dbms=csv 
        replace;
        getnames=yes;
        delimiter=';';
run;

Why am I getting an error and when should I use " and '?

CodePudding user response:

The answer is that macro variables do not resolve within single quotes, but only double quotes.

See this small example.

%let m = 100;

data _null_;
   put 'SINGLE QUOTES: The value of m is &m.';
   put "DOUBLE QUOTES: The value of m is &m.";
run;

CodePudding user response:

Single quotes won't work for macro variables, as macro processor ignores whatever is inside single quotes. Macro triggers like % or & will be ignored and everything inside quotes will be considered a string. That doesn't happen when using double quotes, as the text inside gets tokenised and put into macro processor.

CodePudding user response:

Why am I getting an error and when should I use " and '?

You are getting an error because the name of the file does not start with an ampersand. Quoted strings bounded by single quotes are ignored by the macro processor.

So use double quotes when you want the macro processor to evaluate the string before passing it onto SAS to execute. And use single quotes when you do NOT want the macro processor to modify the string, for example when you want any & or % characters to be part of the string.

  • Related