Hi.
For reading data through cards, with delimited data, this would suffice:
data l;
length NO 8 ADDRESS $200 CITY $50 AGE 8;
input; * read line;
* split line;
NO=inputn(scan(_infile_,1,','),'best.');
CITY=reverse(scan(reverse(_infile_),2,','));
AGE=inputn(reverse(scan(reverse(_infile_),1,',')),'best.');
ADDRESS=scan(_infile_,2,',');
cards;
1, main road near hospital ,mumbai, 30
2,govt area ,pune,38
3,central area,near adminstrative building ,Patna,40
run;
But this code will not have the desired behavior for the 3rd row.
For this, use regular expression parsing:
data l;
length NO 8 ADDRESS $200 CITY $50 AGE 8;
input;
drop _:;
* prepare reg. expression for text parsing;
_EXPR='s/([ 0-9]*),(.*),(.*),([ 0-9]*)/\1#\2#\3#\4/i';
_REGX=prxparse(_EXPR);
_PRX=prxchange(_REGX,1,_infile_);
* split parsed text into desired variables;
NO=inputn(cats(scan(_PRX,1,'#')),'best.');
ADDRESS=cats(scan(_PRX,2,'#'));
CITY=cats(scan(_PRX,3,'#'));
AGE=inputn(cats(scan(_PRX,4,'#')),'best.');
cards;
1, main road near hospital ,mumbai, 30
2,govt area ,pune,38
3,central area,near adminstrative building ,Patna,40
run;
Check here for regular expression info:
http://www.regular-expressions.info/tutorial.html
Check here for the regular expression functions online documentation:
http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a002295977.htm
Cheers from Portugal.
Daniel Santos @
www.cgd.pt.