DATA Step, Macro, Functions and more

import list style data

Reply
Contributor
Posts: 61

import list style data

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;

 

Frequent Contributor
Posts: 95

Re: import list style data

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 (TS1M4) X64_7PRO WIN 6.1.7601 Service Pack 1 Workstation

Contributor
Posts: 61

Re: import list style data

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

Super User
Posts: 10,028

Re: import list style data

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;

Frequent Contributor
Posts: 149

Re: import list style data

@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.
Super User
Super User
Posts: 7,050

Re: import list style data

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

Ask a Question
Discussion stats
  • 5 replies
  • 135 views
  • 2 likes
  • 5 in conversation