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