- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 05-12-2011 05:11 PM
(10567 views)
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Maybe Op want this:
[pre]
data _null_;
file "c:\wa.txt";
set sashelp.class;
put (name sex age weight height) (+(-1));
run;
[/pre]
Ksharp
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Ksharp,
Thanks for your solution. It woks fine.
Thanks
nithi
Thanks for your solution. It woks fine.
Thanks
nithi
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
> [pre]
> data _null_;
> file "c:\wa.txt";
> t sashelp.class;
> put (name sex age weight height) (+(-1));
> run;
> [/pre]
>
> Ksharp
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks! I can use this!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Is there a way to do it with functions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
[pre]
data temp;
length row $ 200;
set sashelp.class;
row=cats(of _all_);
run;
[/pre]
Ksharp
data temp;
length row $ 200;
set sashelp.class;
row=cats(of _all_);
run;
[/pre]
Ksharp
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Ksrshap i have one question
If you want only one line?
Something like that
PeterMPatrickF
Enrique.
If you want only one line?
Something like that
PeterMPatrickF
Enrique.