?
Solved

sas output to fixed width .txt file

Posted on 2010-01-08
13
Medium Priority
?
4,664 Views
Last Modified: 2013-11-16
How to convert sas a final output sas dataset to a fixed width .txt file. Please help
0
Comment
Question by:aruku
  • 7
  • 6
13 Comments
 
LVL 9

Expert Comment

by:bradanelson
ID: 26212648
Here is an example of a simple way to create a fixed width .txt file from a SAS dataset.

Each field has a length of 20.

DATA _NULL_;
    FILE "C:\data\filename.txt" LRECL=80 PAD;
    SET [SAS Dataset];

    PUT
        @01 FieldOne
        @21 FieldTwo
        @41 FieldThree
        @61 FieldFour
        ;
RUN;
0
 

Author Comment

by:aruku
ID: 26212843
if we have already given all the justifications and other formats in the final dataset  then there is no need to mention the justifications at this point right.......
0
 
LVL 9

Expert Comment

by:bradanelson
ID: 26212870
True, but you can.  At this point, it trial and error until you get exactly what you want for the output.  I hope the example helped steer you in the right direction.  Let me know if you have any more quesitons.

Thanks

This works too:

DATA _NULL_;
    FILE "C:\data\filename.txt" LRECL=80 PAD;
    SET [SAS Dataset];

    PUT
        @01 FieldOne    $20.
        @21 FieldTwo    $20.
        @41 FieldThree    $20.
        @61 FieldFour    $20.
        ;
RUN;
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:aruku
ID: 26294185
I am getting the obs in the .txt file as combined and i need to get the label too. How can i create spaces in between the columns but with the same length.

for example

obs 1     obs 2
12           a


I am  getting as 12a in the text file and the heading as obs is also not given.'


please help
0
 
LVL 9

Expert Comment

by:bradanelson
ID: 26294297
Looks like you need to adjust your start position of your 2nd variable.

Example:
I' guessing the code is something like this:
DATA _NULL_;
    FILE [filepath\nane] [options];
    SET [dataset];

    PUT @1 obs1
        @3 obs2;
RUN;

To space the 2nd variable by one you adjust the @3 to @4.  This will move the starting position of the 2nd variable over by 1.

To get the variable name as a header you can force it by doing this:
DATA _NULL_;
    FILE [filepath\nane] [options];
    SET [dataset];

    IF _N_=1 THEN DO;
        PUT @1 "obs1"
            @6 "obs2";
    END;

    PUT @1 obs1
        @6 obs2;
RUN;
0
 

Author Comment

by:aruku
ID: 26294510
The lables i have mentioned in the if condiiton as if_n_ = 1 then do;
'observation1' @6 'observation2' @9

i am getting observation2 as obs   is there any way I can mention more length only to this not to row
0
 
LVL 9

Expert Comment

by:bradanelson
ID: 26294578
The @[n] is the starting position of the string that follows.  If you do what you just did, you are over writing the previous string.  You need to make sure you adjust the @[n] where you will not be over writing the previous string.  Since 'observation2' is 12 char in length, the you need to start the next string 'at least 12 more over from the previous start position.  So if you start 'observation2' @6, the you need to start your next string at least @18 if not @19 to show a space between.  You can put your values at different @[n] than your headers, but the header and values will not line up correctly.  If you want more help on this, I would like to see the code you are writing.
0
 

Author Comment

by:aruku
ID: 26295654
other than increasing the length in the input pointer can't we add any delimiters to atleaset seperate the obs from each other..........

0
 
LVL 9

Expert Comment

by:bradanelson
ID: 26295726
sure, but you are now going to be a delimited file, not a fixed width.  what are your needs?
0
 

Author Comment

by:aruku
ID: 26295947
I need to create a fixed width file not a delimited.......then i think i can't do anything else then leaving it the same way as it is
0
 
LVL 9

Expert Comment

by:bradanelson
ID: 26295960
Do you mind sharing your code (and output)?  It would be very helpfull to see what you are doing and what you want to do.
0
 

Author Comment

by:aruku
ID: 26296061
data _null;
set learn.one;
file '                     ' lrecl = 320 pad;
if _n_ = 1 then do;
put
 @7 'learn1'  @13 'learn2' @20 learn3 ;
end;
put

@7 learn1 $6.
@13 learn2 $6.
@20 learn3 $6.
;
run;



output


learn1laern2learn3
122333313456431234534
212334454345656754556
132235546576768558677

i
0
 
LVL 9

Accepted Solution

by:
bradanelson earned 2000 total points
ID: 26296231
I'm guessing this is not your actual code.  learn3 is not single quoted and learn2 is laern2 in the output.  Plus, there are 3 extra numbers at the end of the output line.  Am I missing something?  You could try adjusting to the following and see what the outcome is.

data _null;
set learn.one;
file '                     ' lrecl = 320 pad;
if _n_ = 1 then do;
put
 @7 'learn1'  @14 'learn2' @21 'learn3' ;
end;
put

@7 learn1 $6.
@14 learn2 $6.
@21 learn3 $6.
;
run;
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question