BookmarkSubscribeRSS Feed
rohitkrishna
Calcite | Level 5

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 

 

13 REPLIES 13
andreas_lds
Jade | Level 19

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.

rohitkrishna
Calcite | Level 5
Hi andreas_lds,
thanks for the quick replay
please find the below input test data
{
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
}
Thanks & Regards
Rohit
yabwon
Onyx | Level 15

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



rohitkrishna
Calcite | Level 5
Hi yabwon,
Thanks for the quick response
I tried with the above code but I am able to get the spaces and comma dlm but test2 - test6 fields data has missed please find the below output after running the above code
{
0230533124, , , , , ,
0220212484, , , , , ,
0401092276, , , , , ,
0401104968, , , , , ,
0401108573, , , , , ,
0401132109, , , , , ,
0674579726, , , , , ,
0513179287, , , , , ,
0513179364, , , , , ,
0513179511, , , , , ,
}
Thanks & Regards
Rohit
yabwon
Onyx | Level 15

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.

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



rohitkrishna
Calcite | Level 5
Hi yabwon,
Thanks for the response
Ya tried the above code the results have as shown in the input & moreover I am using the input file instead of cards
{ 0230533124, , , , , ,
0220212484, , , , , ,
0401092276, , , , , ,
0401104968, , , , , ,
0401108573, , , , , ,
0401132109, , , , , ,
0674579726, , , , , ,
0513179287, , , , , ,
0513179364, , , , , ,
0513179511, , , , , ,}
Thanks & Regards
Rohit


Amir
PROC Star

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.

rohitkrishna
Calcite | Level 5
Hi Amir,
Thanks for the understanding I tried above code some have I getting the results but not it as expected while using the traswrd function we are able getting the space but the comma sparter has missing plase find the below code
{DATA S_FRMT;
FORMAT TEST1 Z10.;
INFILE CLSTA2C MISSOVER DSD DLM=',';
INPUT
TEST1 $
TEST2 $
TEST3 $
TEST4 $
TEST5 $
TEST6 $
;
TEST1 = TRANWRD(TEST1,',',' ,');
TEST2 = TRANWRD(TEST2,',',' ,');
TEST3 = TRANWRD(TEST3,',',' ,');
TEST4 = TRANWRD(TEST4,',',' ,');
TEST5 = TRANWRD(TEST5,',',' ,');
TEST6 = TRANWRD(TEST6,',',' ,');
RUN;
DATA IHUB_FT;
SET S_FRMT;
FILE SYSOUT;
PUT TEST1
TEST2
TEST3
TEST4
TEST5
TEST6;
RUN; }

++++++++++++++++++++++++++++++
{ and the output has
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
0674579726 N Y N S J
0513179287 N Y N S J
0513179364 N Y N S J
0513179511 N Y N S J}
i req comma sparter kindly help on it
Thanks & Regards
Rohit
Amir
PROC Star

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.

rohitkrishna
Calcite | Level 5
Hi Amir,
Thanks for the response
superb it's working fine, thanks a lot
Thanks & Regards
Rohit
Amir
PROC Star

No problem. Please mark whichever post you want to as the solution.

 

Regards,

Amir.

data_null__
Jade | Level 19

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
Tom
Super User Tom
Super User

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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 13 replies
  • 1141 views
  • 0 likes
  • 6 in conversation