Search code examples
sqlsasenterprise-guide

What is the difference between single and double qoutes in SAS and why does single quotes fail when I import data


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 '?


Solution

  • 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.