DATA Step, Macro, Functions and more

Any way to preserve spaces when using put (_ALL_) ?

Accepted Solution Solved
Reply
PROC Star
Posts: 1,760
Accepted Solution

Any way to preserve spaces when using put (_ALL_) ?

 

With this data A='aa'; B=' '; C='cc';

 

I need the flat file output to be

aa| |cc

and not

aa||cc

 

put (_ALL_) (+1) and option dsd is the closest I have been to the desired result, but all strings then have a leading space, which is wrong.

 

Any way to not remove spaces when using put (_ALL_)?

 

Thanks

 

 

 


Accepted Solutions
Solution
‎03-06-2017 10:37 PM
Super User
Posts: 10,041

Re: Any way to preserve spaces when using put (_ALL_) ?

Then DO NOT use DSD .

 

 
 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 51         
 52         filename x temp;
 53         data _null_;
 54         file x dlm='|';
 55          A='aa'; B=' '; C='cc';
 56          put (_all_) (:);
 57         run;
 
 NOTE: The file X is:
       Filename=/tmp/SAS_workD06A00000944_localhost.localdomain/#LN00030,
       Owner Name=sasdemo,Group Name=sas,
       Access Permission=-rw-rw-r--,
       Last Modified=06Mar2017:18:26:48
 
 NOTE: 1 record was written to the file X.
       The minimum record length was 7.
       The maximum record length was 7.
 NOTE: DATA statement used (Total process time):
       real time           0.02 seconds
       cpu time            0.03 seconds
       
 
 58         
 59         data _null_;
 60         infile x;
 61         input;
 62         put _infile_;
 63         run;
 
 NOTE: The infile X is:
       Filename=/tmp/SAS_workD06A00000944_localhost.localdomain/#LN00030,
       Owner Name=sasdemo,Group Name=sas,
       Access Permission=-rw-rw-r--,
       Last Modified=06Mar2017:18:26:48,
       File Size (bytes)=8
 
 aa| |cc
 NOTE: 1 record was read from the infile X.
       The minimum record length was 7.
       The maximum record length was 7.
 NOTE: DATA statement used (Total process time):
       real time           0.03 seconds
       cpu time            0.03 seconds
       
 
 64         
 65         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 75         

View solution in original post


All Replies
Regular Contributor
Posts: 234

Re: Any way to preserve spaces when using put (_ALL_) ?

Hello,

 

put (_ALL_) (+0) ?

Regular Contributor
Posts: 234

Re: Any way to preserve spaces when using put (_ALL_) ?

Sorry, i misread the question and thought you wanted to remove spaces.
Super User
Super User
Posts: 7,977

Re: Any way to preserve spaces when using put (_ALL_) ?

Out of interest, why?  

aa||cc

The above would be the standard format of a delimited file - || indicating missing, be that either character or numeric depending on the data spec.  So what value does adding a space actually give, doesn't it just confuse the issue, e.g. variable is read in as a numeric, but actually contains a space?

PROC Star
Posts: 1,760

Re: Any way to preserve spaces when using put (_ALL_) ?

@RW9 Hadoop can store blank strings as empty strings or nulls.

Solution
‎03-06-2017 10:37 PM
Super User
Posts: 10,041

Re: Any way to preserve spaces when using put (_ALL_) ?

Then DO NOT use DSD .

 

 
 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 51         
 52         filename x temp;
 53         data _null_;
 54         file x dlm='|';
 55          A='aa'; B=' '; C='cc';
 56          put (_all_) (:);
 57         run;
 
 NOTE: The file X is:
       Filename=/tmp/SAS_workD06A00000944_localhost.localdomain/#LN00030,
       Owner Name=sasdemo,Group Name=sas,
       Access Permission=-rw-rw-r--,
       Last Modified=06Mar2017:18:26:48
 
 NOTE: 1 record was written to the file X.
       The minimum record length was 7.
       The maximum record length was 7.
 NOTE: DATA statement used (Total process time):
       real time           0.02 seconds
       cpu time            0.03 seconds
       
 
 58         
 59         data _null_;
 60         infile x;
 61         input;
 62         put _infile_;
 63         run;
 
 NOTE: The infile X is:
       Filename=/tmp/SAS_workD06A00000944_localhost.localdomain/#LN00030,
       Owner Name=sasdemo,Group Name=sas,
       Access Permission=-rw-rw-r--,
       Last Modified=06Mar2017:18:26:48,
       File Size (bytes)=8
 
 aa| |cc
 NOTE: 1 record was read from the infile X.
       The minimum record length was 7.
       The maximum record length was 7.
 NOTE: DATA statement used (Total process time):
       real time           0.03 seconds
       cpu time            0.03 seconds
       
 
 64         
 65         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 75         
PROC Star
Posts: 1,760

Re: Any way to preserve spaces when using put (_ALL_) ?

Mmm...  I had dsd there for a reason, but I can't think of why now.

 

The issue is not solved when commas (for example) are used as a delimiter and values with commas (for example) must be quoted, but that's not my case.

 

I probably wanted a universal solution.

 

Not my current need, but I someone knows of a way to preserve the space when values can contain the delimiter and must therefore be quoted automatically, I am still interested.

 

Super User
Posts: 10,041

Re: Any way to preserve spaces when using put (_ALL_) ?

You can quote it mannually , I think it is easy for you.

 

if findc(x,',') then x=quote(x);

 

put x;

 

 

the alternative way is after you get  xx||yy ,you can change it into xx| |yy by tranwrd. I think it is  easy for you too.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 164 views
  • 1 like
  • 4 in conversation