DATA Step, Macro, Functions and more

export sas dataset to be a sas code file

Reply
Contributor
Posts: 22

export sas dataset to be a sas code file

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

PROC Star
Posts: 7,467

Re: export sas dataset to be a sas code file

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

 

Contributor
Posts: 22

Re: export sas dataset to be a sas code file

data have only have one variable:col

and 5 rows

 

I want to export to be a file.sas

 

Thanks

 

Contributor
Posts: 22

Re: export sas dataset to be a sas code file

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

Super User
Super User
Posts: 7,942

Re: export sas dataset to be a sas code file

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.

PROC Star
Posts: 7,467

Re: export sas dataset to be a sas code file

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

 

Contributor
Posts: 22

Re: export sas dataset to be a sas code file

Works well. Thanks
Respected Advisor
Posts: 4,173

Re: export sas dataset to be a sas code file

@Defense

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;
Ask a Question
Discussion stats
  • 7 replies
  • 190 views
  • 0 likes
  • 4 in conversation