BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ChrisNZ
Tourmaline | Level 20

 

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

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

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

7 REPLIES 7
gamotte
Rhodochrosite | Level 12

Hello,

 

put (_ALL_) (+0) ?

gamotte
Rhodochrosite | Level 12
Sorry, i misread the question and thought you wanted to remove spaces.
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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?

ChrisNZ
Tourmaline | Level 20

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

Ksharp
Super User

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         
ChrisNZ
Tourmaline | Level 20

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.

 

Ksharp
Super User

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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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