BookmarkSubscribeRSS Feed
Alankar
Fluorite | Level 6
I have data as below.
var
1
1P

3
3F
2
;
i want to exprt this to text file using file statement.
DATA _NULL_;
SET TEST(OBS = 10000);
FILE 'C:\RDIP_1.TXT';
PUT var;
RUN;

output should be with the same data and if there is only one character the second character should be space.
1 (+ 1 spaces)
1P (no spaces)
(2 spaces)
3 (+ 1 spaces)
(2 spaces)
3F (no spaces)
2 (+ 1 spaces)
2 REPLIES 2
chang_y_chung_hotmail_com
Obsidian | Level 7
Use a format when you put. Here is a simple example. Hope this helps.



   /* test dataset */


   data one;


     length var $2;


     do var = "1""1P""""3""3F""2";


       output;


     end;


   run;


 


   /* print out to a text file */


   filename text temp;


   data _null_;


     set one;


     file text;


     put var $2.;


   run;


 


   /* check */


   data _null_;


     infile text;


     input;


     put "***" _infile_ "***";


   run;


   /* on lst


   ***1 ***


   ***1P***


   ***  ***


   ***3 ***


   ***3F***


   ***2 ***


   */


   filename text clear;

deleted_user
Not applicable
hello,

another possible solution is based on file options lrecl and pad added to your statement:

DATA _NULL_;
SET TEST(OBS = 10000);
FILE 'C:\RDIP_1.TXT' lrecl=2 pad;
PUT var;
RUN;

Marius

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 4131 views
  • 0 likes
  • 3 in conversation