Hello all,
I need help
i want to read a particular lines from text files
eg: Text file is
/*************************************************************/
Name : XYZ
phone : 123564
product : DACXA
NY
prod one two three four
shoe 26 25 45 65
AC 56 89 56 87
Stat 63 45 23 54
/*************************************************************/
,
i need to create a data set with name,Product city and three columns
Name product city prod three
XYZ DACXA NY shoe 45
XYZ DACXA NY AC 56
XYZ DACXA NY stat 23
can anyone help
My suggestion:
data want;
length
line $80.
name product city prod $10
;
retain name product city;
input;
line = _infile_;
if substr(line,1,2) ne '/*' and line > ' ' and substr(line,4,4) ne 'prod';
if scan(line,1) = 'Name' then name = scan(line,3);
else if scan(line,1) = 'product' then product = scan(line,3);
else if countw(line) = 5
then do;
prod = scan(line,1);
three = input(scan(line,4),best.);
output;
end;
else if substr(line,1,1) ne ' ' then city = line;
drop line;
cards;
/*************************************************************/
Name : XYZ
phone : 123564
product : DACXA
NY
prod one two three four
shoe 26 25 45 65
AC 56 89 56 87
Stat 63 45 23 54
/*************************************************************/
;
run;
proc print data=want noobs;
run;
Result:
name product city prod three XYZ DACXA NY shoe 45 XYZ DACXA NY AC 56 XYZ DACXA NY Stat 23
Please use the {i} icon in the future for posting textual data, to prevent accidental formatting by the forum SW.
Hello,
Can any one help me in reading select data from text files
eg:
Name : XYZ
EMPID:9087
PIN:1234
CITY : NY
PROD SALE1 SALE2 SALE3
DVD 21 32 65
TV 25 35 65
i want to read only few columns output
EMPID CIYT SALE3
9087 NY 65
9087 NY 65
Adapt my code. The basic logic is the same.
data x1;
infile 'c:\temp\temp.txt' ;
input @'EMPID' empid & $20. @'CITY' city & $20.;
run;
data x2;
infile 'c:\temp\temp.txt' firstobs=8 truncover;
input PROD : $20. SALE1 SALE2 SALE3;
run;
data want;
set x2;
if _n_=1 then set x1;
empid=scan(empid,-1,':');
city=scan(city,-1,':');
run;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.