BookmarkSubscribeRSS Feed
AlexeyS
Pyrite | Level 9

data test;

infile datalines dlm=',' dsd;

input Product $ Sale dollar6. ExchangeRate 4.2;

datalines;

Boot,29,761$,3.61

Men's Casual,67,242$,3.5

Sport Shoe,1,690$,3.48

;

run;

 

5 REPLIES 5
Norman21
Lapis Lazuli | Level 10

Perhaps this can help?

 

http://documentation.sas.com/?docsetId=lestmtsref&docsetTarget=n0lrz3gb7m9e4rn137op544ddg0v.htm&docs...

 

"Example 2: Reading Character Data That Contains Embedded Blanks"

Norman.
SAS 9.4 (TS1M6) X64_10PRO WIN 10.0.17763 Workstation

AlexeyS
Pyrite | Level 9

Hi, thank you for your help, but this is not the same case.

Ksharp
Super User
Your data are totally messed up.

data test;
infile datalines ;
input ;
p=find(_infile_,',');
product=substr(_infile_,1,p-1);

_infile_=substr(_infile_,p+1);
p=find(_infile_,'$');
sale=input(substr(_infile_,1,p),comma32.);

_infile_=substr(_infile_,p+1);
ratio=input(_infile_,comma32.);

drop p;
datalines;
Boot,29,761$,3.61
Men's Casual,67,242$,3.5
Sport Shoe,1,690$,3.48
;
run;

error_prone
Barite | Level 11
@AlexeyS are the numbers of "sale" always at least 4 digits? I would contact the person that provided the data and request a csv-file complying with csv-file specs.
Tom
Super User Tom
Super User

So your source data is not formatted properly for anything.  You cannot use comma as the delimiter and also have comma in the values. If your values contain the delimiter character then they need to be in quotes.  Like this:

Boot,"29,761$",3.61
Men's Casual,"67,242$",3.5
Sport Shoe,"1,690$",3.48

But the presence of the $ after the value does present a method that might make it possible to read the data.

data fixed;
  infile datalines dlm=',' dsd truncover column=cc;
  length Product $20 Sale 8 ExchangeRate 8;
  input product @ ;
  start=cc ;
  input @'$' @ ;
  sale=input(substrn(_infile_,start,cc-start-1),comma32.);
  input @cc+1 ExchangeRate ;
  drop start;
datalines;
Boot,29,761$,3.61
Men's Casual,67,242$,3.5
Sport Shoe,1,690$,3.48
;

image.png

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5 replies
  • 958 views
  • 2 likes
  • 5 in conversation