I have a data that is 1 single long line.
I am trying to get the value of f1 or myvar variable value inside the find function as an argument but the find function is not reading the f1 or myvar value.
I want an output as the a2 in the attached csv file but I don’t want to hardcode it.
There can be a maximum of 40 LX* segments within a claimnumber. I only have two LX lines as an example in the sample data.
THE pic SHOWS WHAT I WANT.
How can I read the value of f1 or myvar inside the find function.
My Code :
%macro tri;
data S11;
infile "E:\Users\Documents and Settings\57260\Desktop\Learning\NYS\TR.NYE40024.837IM.B.181101101518.001.DAT.VO" dlmStr ='PRV*BI*PXC*' lrecl = 1000000000 ignoredoseof ;
input String : $2000. @@;
Claimno= Scan(substr(string,find(string,'~CLM*')+ 5,20),1,'*');
%do i = 1 %to 2;
f1=cats("'~LX*",&i.,"~SV2*'");
CALL SYMPUT('A'||LEFT(_N_), f1) ;
myvar = symget('A1');
z1= find(string,"&A1.");
z2= find(string,'~LX*1~SV2*');
a1=sUBstr(string,find(String,f1)+5,19);
b1=sUBstr(string,find(String,myvar)+5,19);
a2= sUBstr(string,find(string,'~LX*1~SV2*')+5,19);
output;
%put &i;
%END;
RUN;
%mend tri;
%tri;
I will appreciate your help in this regardThis is what I want
add a line something like below showing what u have in one variable and how your other variables should be. someone can easily help you.
have;
var="CLM*011021151034600001*110.89***73:A:1**C*Y*I~DTP*434*RD8*2015100820151008~CL1*3*2*01~NTE*ADD*87799~HI*ABK:F331~NM1*82*1*P*****XX*1295911063~NM1*77*2******XX*93009~SBR*P*18*02914056*02914056**6***16~AMT*D*21~AMT*EAF*0~NM1*PT"
var1 = just describe what it should be
var2= just describe it should be
I just added a csv file which shows what i want
it is very difficult to visualize that way, if you use running man button and just paste the same, it will make answering person task easy
Avoid using Call symput here. It will not work the way your thinking. The data step has to end inorder to call the macro variables created by call symput, this is the common mistake many users make. Your creating a macro variable using call symput and then calling the macro variable using symget, you can't do that because there is no macro variable created yet.
"You cannot use a macro variable reference to retrieve the value of a macro variable in the same program (or step) in which SYMPUT creates that macro variable and assigns it a value."
Why don't you avoid creating a macro and just give the second argument in Find() a variable.
%do i = 1 %to 2;
f1=cats("'~LX*",&i,"~SV2*'");
myvar = f1;
z1= find(string,f1); /* second argument can be a variable name */
z2= find(string,'~LX*1~SV2*');
a1=sUBstr(string,find(String,f1)+5,19);
b1=sUBstr(string,find(String,myvar)+5,19);
a2= sUBstr(string,find(string,'~LX*1~SV2*')+5,19);
output;
%end;
f1 is a variable name but SAS doesn't recognize it and i get a value of 0
What is the output your trying to get from the lengthy string you gave. I don't see anything in the csv file.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: