BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
thogir28
Calcite | Level 5

Hello,

 

I have a txt file that contains multiple equations which are separated by ";". 

Some equations are splited into 2 records because they are very long. 

In the example below eq1 and eq3 are not separated but eq2 is:

 

eq1 = x1*a+ x2*b + x3*c ;

eq2 = x1*a + x2*b +

x3*c + x4*d ; 

eq3 = x1*a + x2*b + x3*c ; 

 

I want to create a dataset with only 1 variable that contains one row for each equations like that : 

VAR1

eq1=eq1 = x1*a+ x2*b + x3*c

eq2 = x1*a + x2*b +x3*c + x4*d

eq3 = x1*a + x2*b + x3*c

 

The basic code to import is : 

 

data temp;
infile "txt_file" dlm=";" ;
input var1 :$1000.;
run;

 

I tried many things but nothing works. Every time SAS creates 2 rows for the splitted equations. I know with this exemple you can just add a data step after the import and concatenate the 2 separeted row for the equation 2 but I cannot do that with my real data.

 

Thank you for your help.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Try this:

data want;
infile datalines4 truncover;
input equation $400.;
do while (substr(equation,length(equation),1) ne ';');
  input add_line $200.;
  equation = catx(' ',equation,add_line);
end;
drop add_line;
datalines4;
eq1 = x1*a+ x2*b + x3*c ;
eq2 = x1*a + x2*b +
x3*c + x4*d ; 
eq3 = x1*a + x2*b + x3*c ;
;;;;
run;

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

Try this:

data want;
infile datalines4 truncover;
input equation $400.;
do while (substr(equation,length(equation),1) ne ';');
  input add_line $200.;
  equation = catx(' ',equation,add_line);
end;
drop add_line;
datalines4;
eq1 = x1*a+ x2*b + x3*c ;
eq2 = x1*a + x2*b +
x3*c + x4*d ; 
eq3 = x1*a + x2*b + x3*c ;
;;;;
run;
thogir28
Calcite | Level 5

It works ! Thank you. 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 719 views
  • 3 likes
  • 2 in conversation