We have a requirement to enclose a variable values in double quotes and output a txt file.
To do that we have used quote function and also quote format. They look fine in the SAS but when we output using proc export its giving the 3 double quotes instead of single double quote before and after the variable value.
We are using the below code as example:
data fr;
set sashelp.cars;
/*format model quote.;*/
model=quote(model);
run;
filename test 'path\T1.txt' ;
proc export data = fr
outfile = test
DBMS=tab REPLACE;
run;
Expected variable value- "value"
Quote function result -"""value"
Quote format result-"""value"""
You're not getting what you think from QUOTE function. READ THE DOCUMENTATION.
QUOTE quotes the entire value including trailing blanks and when the value is assigned back the variable length is not sufficient.
Fascinating: proc exports quotes the quotes. Same happens, when using the quote-format in a datastep using file and put to export the data. Using quote + strip seems to create the expected result.
data _null_;
set sashelp.cars;
file "PATH\T1.txt";
length Buffer $ 250;
Buffer = catx('09'x, Make, quote(strip(Model)), Type, Origin, DriveTrain, MSRP, Invoice,
EngineSize, Cylinders, Horsepower, MPG_City, MPG_Highway, Weight, Wheelbase, Length);
put Buffer;
run;
You're not getting what you think from QUOTE function. READ THE DOCUMENTATION.
QUOTE quotes the entire value including trailing blanks and when the value is assigned back the variable length is not sufficient.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: