BookmarkSubscribeRSS Feed
BobyGadu
Calcite | Level 5

sorry about my data Smiley Happy but why are you specifically doing for first 3 records and first 5 records

art297
Opal | Level 21

It not the first three (and five) records but, rather, the first three variables and the last five variables.

The code is changing the commas to semicolons for all fields except the fourth one, the one that can contain embedded commas.

Then it is simply reading the record, using semicolons as the delimiter and only expecting to possibly confront commas when reading the fourth field.

BobyGadu
Calcite | Level 5

Thank you its gr8 function I ever came across thank you very much to learn about this

data_null__
Jade | Level 19
data dollar;
   infile cards dsd column=col;
   input (a b c)($) @;
   call scan(_infile_,-5,p,l,',');
   l = p-col-1;
  
input amv $varying32. l +1 d $ e:percent. f $ g $ h :percent.;
  
cards;
a,b,c,$200,x,0.0%,xy,sd,12.90%
z,c,d,$123,456,789,g,9.0%,aw,fr,78.78%
;;;;
RichardinOz
Quartz | Level 8

You may not have any control over the source of the CSV, but if you do and it comes out of Excel, you could request a tab delimited file as source instead.  This is just as easy to produce from Excel, and can be read with the standard Proc Import in SAS.  The advantages are:  commas in the value are no longer a problem, no non standard code to maintain, and any additional columns which might be introduced into the data will be dealt with automatically.

I would also advocate use of the comma informat.

Richard

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 19 replies
  • 6360 views
  • 5 likes
  • 6 in conversation