I try to export a sas dataset (have) to sas code file (want) using the following code.
PROC EXPORT DATA= mysasdat.have
OUTFILE= "C:\Users\weig3\Desktop\want.sas"
DBMS=TAB REPLACE;
PUTNAMES=NO;
RUN;
have (SAS7bdat)
COL
proc format ;
value DFSTATv 0 = "lost"
1 = "clean"
"2 = "dirty"
3 = ""error"
The output “want” belw show an extra “ “ as compare to the original “have”.
proc format ;
"value DFSTATv 0 = ""lost"""
"1 = ""clean"""
"2 = ""dirty"""
"3 = ""error"""
Any idea for don't having the extra “ “ ?
Thanks
I don't see how you ended up with proc format code, with or without the extra quotes, based on the code you say you ran.
Please provide an example, using the insert code {i} icon above, that contains data in the form of a data step AND all of the code you ran to get the result you are asking about.
Art, CEO, AnalystFinder.com
data have only have one variable:col
and 5 rows
I want to export to be a file.sas
Thanks
sorry for confused, here is my data, output and code I used
data have:
obs COL
1 proc format ;
2 value DFSTATv 0 = "lost"
3 1 = "clean"
4 2 = "dirty"
5 3 = ""error
data I got(output)
proc format ;
"value DFSTATv 0 = ""lost"""
"1 = ""clean"""
"2 = ""dirty"""
"3 = ""error"""
Code I use:
PROC EXPORT DATA= mysasdat.have
OUTFILE= "C:\Users\weig3\Desktop\want.sas"
DBMS=TAB REPLACE;
PUTNAMES=NO;
Run;
RUN;
Help need:
avoid to have extra " " in want (as compare to have )
Thanks
Why do you have SAS code in a dataset, sounds bad to me. What exactly is it your trying to achieve. If its textual comparisons, use a text compare program, if you want to save formats then either put it straight in a text file, or have a dataset which can be read in by cntlin. Much like putting SAS code in Excel, I really wouldn't recommend it.
Then I would just use something like:
data have; informat col $50.; input col &; cards4; proc format ; value DFSTATv 0 = "lost" 1 = "clean" 2 = "dirty" 3 = "error" run; ;;;; data _null_; file 'c:\art\want.sas'; set have; put col; run;
Art, CEO, AnalystFinder.com
And if you just want to execute and compile the format then use option 2 in below script.
data have;
infile datalines truncover;
input col $char80.;
datalines4;
proc format ;
value DFSTATv
0 = "lost"
1 = "clean"
2 = "dirty"
3 = "error"
;
run;
;;;;
run;
/* option 1: Write code to .sas file on desktop of user */
data _null_;
file "%sysget(userprofile)\Desktop\want.sas";
set have;
put @1 col $char.;
run;
/* option 2: Write code SAS WORK location and the execute it */
filename code temp;
data _null_;
file code;
set have;
put @1 col $char.;
run;
%include code /source2;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.