Hello Team ,
we are having below text in the end of XML file
<link rel="next" href="http://spappfarm.opintra.fi/iapps/testsite_uat/_api/Web/Lists/getByTitle('test%20test%20test%20test'..." /></feed>);
%macro GetFileByServerRelativeUrl (out_param=); %global &out_param. test1; %let &out_param.=; data _null_; length text $32767; infile "/out_countryrisk_fi.txt" DSD DLM="09"x ; input; test1=index( _infile_,'next'); put 'this is to test value ' test1 ; call symputx("&out_param.", text); run; %put macro variable &out_param. created with value &&&out_param. ; %mend; %GetFileByServerRelativeUrl ( out_param=ServerUrl_new);
1. am try to search for word 'next' in the XML using
test1=index( _infile_,'next'); where am getting '0' as output
2. how to read the text only in double quotes after the word next in above string
Thanks every one for all your inputs ,
from this i could able to analyse that the input file am reading is more than 32767 , so the lines having the text (next) are truncated .
Here is solution , where am reading the input file morethan 32767 untill end of the file and searching for the string 'next' using find and finally extracting the text in href which are enclosed in doublequotes.
data Test_dataset;
infile " /out_test.txt" lrecl=32767 recfm=f truncover;
input @1 myline $CHAR32767.;
put "the value of _infile_ is:" _infile_ ;
test1=find( _infile_,'next');
text=scan(substr(_infile_, find( _infile_,'next')+11),1,"""");
put 'this is to test value ' text;
run;
Hi,
Your use of INDEX() looks fine to me, e.g. below works:
data _null_ ;
string="<link rel=""next"" href=""http://spappfarm.opintra.fi/iapps/testsite_uat/_api/Web/Lists/getByTitle('test%20test%20test%20test'..."" /></feed>);" ;
test1=index(string,'next');
put string= test1=;
run ;
Note that your XML file likely has multiple lines, and this will be checking every line to see if it has the string "next" on in it.
To debug, I suggest you change your PUT statement to:
put 'this is to test value ' test1= _infile_ ;
That should let you check that the _infile_ variable has the value you intend.
Your original code works for me. Here is an example where I write a file, and then read in the file using your original code. I added a PUT statement to show the value of _infile_.
*generate an input file;
data _null_ ;
file "Q:\junk\foo.txt" ;
put "<link rel=""next"" href=""http://spappfarm.opintra.fi/iapps/testsite_uat/_api/Web/Lists/getByTitle('test%20test%20test%20test'..."" /></feed>);" ;
put "hello world" ;
run ;
*Read in the file ;
data _null_;
infile "Q:\junk\foo.txt" DSD DLM="09"x ;
input;
test1=index( _infile_,'next');
put "the value of _infile_ is:" _infile_ ;
put 'this is to test value ' test1;
run;
Log is:
10 *Read in the file ; 11 data _null_; 12 infile "Q:\junk\foo.txt" DSD DLM="09"x ; 13 input; 14 test1=index( _infile_,'next'); 15 put "the value of _infile_ is:" _infile_ ; 16 put 'this is to test value ' test1; 17 run; NOTE: The infile "Q:\junk\foo.txt" is: Filename=Q:\junk\foo.txt, RECFM=V,LRECL=32767,File Size (bytes)=154, Last Modified=17Aug2022:08:03:28, Create Time=17Aug2022:07:54:47 the value of _infile_ is: <link rel="next" href="http://spappfarm.opintra.fi/iapps/testsite_uat/_api/Web/Lists/getByTitle('test% 20test%20test%20test'..." /></feed>); this is to test value 12 the value of _infile_ is:hello world this is to test value 0 NOTE: 2 records were read from the infile "Q:\junk\foo.txt". The minimum record length was 11. The maximum record length was 139.
Here's a theory as to the cause ... it should be easy for you to test.
When your INPUT statement ends, it releases the current line of raw data. That updates the value of _INFILE_. So make a small change to your program to hold on to the current line of raw data just a little bit longer: Where you have:
input;
change it to:
input @;
Are you just looking for the HREF= values that appear after the NEXT string?
data want ;
infile "/out_countryrisk_fi.txt" DSD DLM='<= >' ;
input @'"next"' @ '"href"=' text :$32767. @@ ;
run;
Thanks every one for all your inputs ,
from this i could able to analyse that the input file am reading is more than 32767 , so the lines having the text (next) are truncated .
Here is solution , where am reading the input file morethan 32767 untill end of the file and searching for the string 'next' using find and finally extracting the text in href which are enclosed in doublequotes.
data Test_dataset;
infile " /out_test.txt" lrecl=32767 recfm=f truncover;
input @1 myline $CHAR32767.;
put "the value of _infile_ is:" _infile_ ;
test1=find( _infile_,'next');
text=scan(substr(_infile_, find( _infile_,'next')+11),1,"""");
put 'this is to test value ' text;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.