BookmarkSubscribeRSS Feed
sonyk
Calcite | Level 5
I have to export a data set to text file.But the values should not be separated by any delimiter including the default delimiter.I mean the text file values should not be separated by space or comma or any thing.Can any one please help me out how to do this?
13 REPLIES 13
Cynthia_sas
SAS Super FREQ
Hi:
I am having a hard time understanding how you're actually going to USE this resulting text file. For example, consider SASHELP.CLASS -- the rows for Alfred and Alice:
[pre]
Name Sex Age Height Weight
Alice F 13 56.5 84.0
Alfred M 14 69.0 112.5
[/pre]

Without ANY delimiters or space, your text file would look like:
[pre]
AlfredM1469.0112.5
AliceF1356.584.0
[/pre]

How would you decide where AGE ended and HEIGHT started??? How would you decide where the NAME ended and what if you had a name like Aloysius and another name like Jay??? How would you know how LONG the value for NAME should be?

With some spaces between the fields, you would have something like this:
[pre]
Alfred M 14 69.0 112.5
Alice F 13 56.5 84.0
[/pre]

SAS could write a file without any delimiters, as shown above, but I question how useful the resulting file would be.

cynthia
sonyk
Calcite | Level 5
Hi ,
Thanks for your response.I am new to SAS.I m doing it for a assignment.I am not going to work with the file in real time.Can you please let me know the proc for writing it in text file without delimiter,.

Thanks,
nithi
art297
Opal | Level 21
Nithi,

I'm sure there is probably an even easier way to do what you need, but the following would do it:
[pre]
data have;
input id x y z;
cards;
001 1 2 3
002 4 5 6
;

data _null_;
file "c:\want.txt";
set have;
put @1 id @;
put @4 x @;
put @5 y @;
put @6 z;
run;
[/pre]
i.e., simply define, with put statements, where you want data written and use the @ modifier to determine whether to end the record.

Art
-----------
> Hi ,
> Thanks for your response.I am new to SAS.I m doing
> it for a assignment.I am not going to work with the
> file in real time.Can you please let me know the
> proc for writing it in text file without
> delimiter,.
>
> Thanks,
> nithi
Ksharp
Super User
Hi.Art.T.
Maybe Op want this:
[pre]
data _null_;
file "c:\wa.txt";
set sashelp.class;
put (name sex age weight height) (+(-1));
run;
[/pre]

Ksharp
sonyk
Calcite | Level 5
Hi Ksharp,
Thanks for your solution. It woks fine.

Thanks
nithi
stateworker
Fluorite | Level 6
KSharp - what does the (+(-1) do? Does that remove the space between the variables where a delimiter would usually go?

> [pre]
> data _null_;
> file "c:\wa.txt";
> t sashelp.class;
> put (name sex age weight height) (+(-1));
> run;
> [/pre]
>
> Ksharp
Ksharp
Super User
Hi.
That means to move point back one position.For example:
put name sex ; will be like this :
Peter M
Patrick F

SAS will move point one postion and then print value of sex,
So If we use put name +(-1) sex +(-1); we will see this:
PeterM
PatrickF

Namely, move back one position for point and print the next value.
(name sex) (+(-1)) is identified with the above.If you want print all variable maybe can use this: (_all_) (+(-1))


Ksharp
stateworker
Fluorite | Level 6
Thanks! I can use this!!!
sonyk
Calcite | Level 5
Hi art,
Thanks for your help.your solution works if we give raw data.so that we know length of id ,X,Y,Z..I am trying with dataset where i know only variable names.

Thanks
nithi
sonyk
Calcite | Level 5
Is there a way to do it with functions?
ballardw
Super User
Create a long string using the CATS Function. Brief example:

data j;
var1= "abc";
var2= 'pdq';
var3= 234.35;
length string $ 1000;
string= cats(var1,var2,(put(var3,f6.1)));
run;

Then export the STRING variable using any of a variety of methods.
Ksharp
Super User
[pre]
data temp;
length row $ 200;
set sashelp.class;
row=cats(of _all_);
run;
[/pre]


Ksharp
erobles55
Calcite | Level 5
Ksrshap i have one question

If you want only one line?

Something like that

PeterMPatrickF

Enrique.

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!

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
  • 13 replies
  • 8835 views
  • 1 like
  • 7 in conversation