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
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
Hello,
put (_ALL_) (+0) ?
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?
@RW9 Hadoop can store blank strings as empty strings or nulls.
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
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.
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.
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.
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.