BookmarkSubscribeRSS Feed
Riteshdell
Quartz | Level 8

Hello expert,

 

I have a CSV File with PIPE (|) delimiter.

If you see below screenshot, I need to handle 7th column data which is going to next 4 lines till next delimiter (|).

lets assume  I have 7th variable name (value) data is starting from marked dark blue color till next 4 lines.

It is reading wrong, every next line data is appearing to next column. so data is showing wrong.

How to handle this situation, can any body help me on same.

 

Note - I have already set enough length of column.

 

"Zeer goed draaiend kantoor waar de produktie de laatste maanden
fors is gestegen.
Heeft ondertussen een zilveren statuut , Naviga- Mauretus is in volle expansie en
zal weldra tot de top drie gaan behoren.
"

 

 

 

DATA.PNG

 

thanks in advance .

7 REPLIES 7
Riteshdell
Quartz | Level 8

Hello expert,

 

I have a CSV File with PIPE (|) delimiter.

If you see below screenshot, I need to handle 7th column data which is going to next 4 lines till next delimiter (|).

lets assume  I have 7th variable name (value) data is starting from marked dark blue color till next 4 lines.

It is reading wrong, every next line data is appearing to next column. so data is showing wrong.

How to handle this situation, can any body help me on same.

 

Note - I have already set enough length of column.

 

"Zeer goed draaiend kantoor waar de produktie de laatste maanden
fors is gestegen.
Heeft ondertussen een zilveren statuut , Naviga- Mauretus is in volle expansie en
zal weldra tot de top drie gaan behoren.
"

 

 

 

DATA.PNG

 

thanks in advance .

mfab
Quartz | Level 8

Hello there,

 

you could make the approach to read in line by line and then decide, what you want to do with your line.

Like so:

 

/* dummy code */
Data
Work.Test (drop=help); Length var1 var2 var3 help $50;
Retain var1 var2 var3 help; Input; If ( countw(_infile_,"|") = 3 ) Then Do;
Output; /* output previous line */ var1 = scan(_infile_,1,"|"); var2 = input(scan(_infile_,2,"|"),??best.);
help = var2; var3 = scan(_infile_,3,"|"); End;
Else Do;
var2 = cat(var2, _infile_);
End; Run;

 

I think you get the idea. Read in the line and if you have the desired number of separators, you can read in all variables with scan.

Now for the lines where you have no "|" , you should take this part and add it to the variable in the previous row.

Please note that this is just an example code above.

This leaves some questions, like what to do if another variable gets too long and cut of and you might find a number of separators ,that you do not expect, etc. etc.

 

This link might also help.

 

It all has to to with checking the line and then deciding what to do with the content 😉

 

Cheers,

Michael

Ksharp
Super User

Here is an example.

 

data have;
infile cards truncover;
input x $800.;
length line $ 20000;
retain line;
line=cats(line,x);
if countc(line,'|')=3 then do;output;call missing(line);end;
drop x;
cards;
1|a|ddfd|dsd
2|b|sds
sds|sdsd 
3|c|s
dskdh|asdf
;
run;
Kurt_Bremser
Super User

Please post textual data into a {i} window, so that

- formatting is preserved

- we can copy/paste it to our SAS for testing

or attach a sample of the file to your post; with this, we can even make sure to see which characters are used for the linebreaks.

 

Kurt_Bremser
Super User

Please post textual data into a {i} window, so that

- formatting is preserved

- we can copy/paste it to our SAS for testing

or attach a sample of the file to your post; with this, we can even make sure to see which characters are used for the linebreaks.

 

Tom
Super User Tom
Super User

It depends on whether the line breaks in the middle of the lines are stored using the same characters as the file uses to mark the end of line.  If you are lucky you can use the TERMSTR= option on the FILENAME or INFILE statement and SAS will be able to tell the difference.

Otherwise search on this site for solutions to this problem.

https://communities.sas.com/t5/General-SAS-Programming/Carriage-Returns-Need-to-be-removed/td-p/8307...

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 7 replies
  • 4558 views
  • 0 likes
  • 5 in conversation