Help using Base SAS procedures

how to export data without delimiters?

Reply
Occasional Contributor
Posts: 9

how to export data without delimiters?

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?
SAS Super FREQ
Posts: 8,742

Re: how to export data without delimiters?

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
Occasional Contributor
Posts: 9

Re: how to export data without delimiters?

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
PROC Star
Posts: 7,360

Re: how to export data without delimiters?

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
Super User
Posts: 9,671

Re: how to export data without delimiters?

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
Occasional Contributor
Posts: 9

Re: how to export data without delimiters?

Hi Ksharp,
Thanks for your solution. It woks fine.

Thanks
nithi
Contributor
Posts: 33

Re: how to export data without delimiters?

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
Super User
Posts: 9,671

Re: how to export data without delimiters?

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
Contributor
Posts: 33

Re: how to export data without delimiters?

Thanks! I can use this!!!
Occasional Contributor
Posts: 9

Re: how to export data without delimiters?

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
Occasional Contributor
Posts: 9

Re: how to export data without delimiters?

Is there a way to do it with functions?
Super User
Posts: 10,483

Re: how to export data without delimiters?

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.
Super User
Posts: 9,671

Re: how to export data without delimiters?

[pre]
data temp;
length row $ 200;
set sashelp.class;
row=cats(of _all_);
run;
[/pre]


Ksharp
Ask a Question
Discussion stats
  • 12 replies
  • 3535 views
  • 0 likes
  • 6 in conversation