Hi All,
we are facing one issue regarding the data with the dlm format please suggest some solution about the below query
input file :
++++++++++++++++++++++++++++++++++++++++++++++++
0230533124,,,,,
0220212484,Y,N,Y,N,N
0401092276,N,Y,N,S,J
0401104968,N,Y,N,S,J
0401108573,N,Y,N,S,J
0401132109,N,Y,N,S,J
total 6 fields
++++++++++++++++++++++++++++++++++++++++++++++++++
the reqirment is
0230533124, , , , ,
0220212484,Y ,N ,Y ,N ,N
0401092276,N ,Y ,N ,S ,J
0401104968,N ,Y ,N ,S ,J
0401108573,N ,Y ,N ,S ,J
0401132109,N ,Y ,N ,S ,J
with the comma sapreter and one space for each field
+++++++++++++++++++++++++++++++++++++++++++++++++
and plz find the below code
DATA S_FRMT;
FORMAT TEST1 Z10.;
INFILE CLSTA2C MISSOVER DSD DLM=',' TRUNCOVER;
INPUT TEST1 $
TEST2 $
TEST3 $
TEST4 $
TEST5 $
TEST6 $
;
RUN;
DATA IHUB_FT;
SET S_FRMT;
FILE SYSOUT;
putTEST2 z10.
TEST3 $char1.
TEST4 $char1.
TEST5 $char1.
TEST6 $char1.;
RUN;
PROC PRINT DATA = IHUB_FT;
RUN;
But I am facing the issue that is all fields are concatenating without comma it printing the data
and i tried with the ||','|| option also that case some fields are missing
my requirement is with comma separator i req the data, please kindly give some solution for the above problem
Thanks & Regards
Rohit
Please post test-data in usable form, so that we can use your program and see what happens.
And please use {i} or running-man icon to post code, log and anything that needs formats to be preserved.
Hi @rohitkrishna ,
Try this one:
DATA S_FRMT;
FORMAT TEST1 Z10.;
INFILE CARDS MISSOVER DSD DLM=',';
INPUT
TEST1 $
TEST2 $
TEST3 $
TEST4 $
TEST5 $
TEST6 $
;
cards;
0230533124,,,,,
0220212484,Y,N,Y,N,N
0401092276,N,Y,N,S,J
0401104968,N,Y,N,S,J
0401108573,N,Y,N,S,J
0401132109,N,Y,N,S,J
;
RUN;
FILENAME SYSOUT TEMP;
DATA _null_;
SET S_FRMT;
array T TEST2 - TEST6;
FILE SYSOUT;
PUT TEST1 +(-1) ", " @;
do over T;
L = lengthn(T);
put T $VARYING. L ", " @;
end;
PUT;
RUN;
All the best
Bart
What are the data in the dataset you have? Do variables contain any values? What was the code you executed?
All the best
Bart
P.S. use the {i} and the [running man] icons to insert data and code.
Hi @rohitkrishna, if I've understood you correctly, you want to output a file the same as the input file, but with a space before each comma.
Based on that understanding, as long as there are no commas in your data values, the following code:
data _null_;
file tempout; /* use your output file */
infile tempin; /* use your input file */
input;
_infile_ = tranwrd(_infile_,',',' ,');
put _infile_;
run;
produces the following output file:
0230533124 , , , , , 0220212484 ,Y ,N ,Y ,N ,N 0401092276 ,N ,Y ,N ,S ,J 0401104968 ,N ,Y ,N ,S ,J 0401108573 ,N ,Y ,N ,S ,J 0401132109 ,N ,Y ,N ,S ,J
Kind regards,
Amir.
The code I provided can be used as it is, all you have to do replace the file reference to "sysout" and the infile reference to "clsta2c":
file sysout; /* use your output file */
infile clsta2c; /* use your input file */
No other code needs to change, just make the above two replacements.
The one data step I posted reads the input file, changes the record it has read and then writes it directly to the output file. No data set or program variables need to be created to do this.
Hope that helps.
Kind regards,
Amir.
No problem. Please mark whichever post you want to as the solution.
Regards,
Amir.
Seems likes DLMSTR=' ,' FILE statement option is what you need.
48 data _null_;
49 file log dlmstr=' ,';
50 set test;
51 put (_all_)(:);
52 run;
0230533124 , , , , ,
0220212484 ,Y ,N ,Y ,N ,N
0401092276 ,N ,Y ,N ,S ,J
0401104968 ,N ,Y ,N ,S ,J
0401108573 ,N ,Y ,N ,S ,J
0401132109 ,N ,Y ,N ,S ,J
It is not clear what you want since you keep posting the fixed text data into the regular body of your post so the forum is showing it in proportional font and potentially flowing text and adding emojis. Make sure to use the pop up windows from the Insert Code or Insert SAS Code icons on the menu bar.
Is this what you want out?
2225 data _null_; 2226 file log; 2227 set have; 2228 put var1 +(-1) (var2-var6) (','); 2229 run; 0230533124, , , , , 0220212484,Y ,N ,Y ,N ,N 0401092276,N ,Y ,N ,S ,J 0401104968,N ,Y ,N ,S ,J 0401108573,N ,Y ,N ,S ,J 0401132109,N ,Y ,N ,S ,J
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.