BookmarkSubscribeRSS Feed
Defense
Obsidian | Level 7

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

7 REPLIES 7
art297
Opal | Level 21

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

 

Defense
Obsidian | Level 7

data have only have one variable:col

and 5 rows

 

I want to export to be a file.sas

 

Thanks

 

Defense
Obsidian | Level 7

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

art297
Opal | Level 21

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

 

Defense
Obsidian | Level 7
Works well. Thanks
Patrick
Opal | Level 21

@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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 2587 views
  • 0 likes
  • 4 in conversation