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

Dear All,

I need to extract a sub set of data from the text file. Here i have attached the input text file .

I have given the output below. when ever i pass the parameter SGT or any other it should extract the data from text file.

 

output:

*SGT
0.005 0.0 0.
0.040 0.005 0.
0.080 0.013 0.
0.120 0.026 0.
0.160 0.040 0.
0.200 0.058 0.
0.240 0.078 0.
0.280 0.100 0.
0.320 0.126 0.
0.360 0.156 0.
0.400 0.187 0.
0.440 0.222 0.
0.480 0.260 0.
0.520 0.300 0.
0.560 0.348 0.
0.600 0.400 0.
0.640 0.450 0.
0.680 0.505 0.
0.720 0.562 0.
0.760 0.620 0.
0.800 0.680 0.
0.840 0.740 0.

1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Onyx | Level 15

Do you mean something like this?:

data want;
  infile cards4 missover;
  input;

  if _INFILE_ =: '*SGT' then
    do until(a=.);
      input;
      a = input(scan(_INFILE_,1," "), ?? best32.);
      b = input(scan(_INFILE_,2," "), ?? best32.);
      if a>. then output;
    end;

cards4;
 **---------------------------- ROCK FLUID -------------------------------
*ROCKFLUID
*RPT
*SGT
      0.005     0.0      0.
      0.040     0.005    0.
      0.080     0.013    0.
      0.120     0.026    0.
      0.160     0.040    0.
      0.200     0.058    0.
      0.240     0.078    0.
      0.280     0.100    0.
      0.320     0.126    0.
      0.360     0.156    0.
      0.400     0.187    0.
      0.440     0.222    0.
      0.480     0.260    0.
      0.520     0.300    0.
      0.560     0.348    0.
      0.600     0.400    0.
      0.640     0.450    0.
      0.680     0.505    0.
      0.720     0.562    0.
      0.760     0.620    0.
      0.800     0.680    0.
      0.840     0.740    0.
*SWT
      0.160     0.0      0.
      0.200     0.002    0.
      0.240     0.010    0.
      0.280     0.020    0.
      0.320     0.033    0.
      0.360     0.049    0.
      0.400     0.066    0.
      0.440     0.090    0.
      0.480     0.119    0.
      0.520     0.150    0.
      0.560     0.186    0.
      0.600     0.227    0.
      0.640     0.277    0.
      0.680     0.330    0.
      0.720     0.390    0.
      0.760     0.462    0.
      0.800     0.540    0.
      0.840     0.620    0.
      0.880     0.710    0.
      0.920     0.800    0.
      0.960     0.900    0.
      0.995     1.0      0.
**-------------------------------- INITIAL CONDITION --------
*INITIAL
*VERTICAL *DEPTH_AVE *WATER_GAS
*REFPRES  3550.0
;;;;
run;

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



View solution in original post

4 REPLIES 4
yabwon
Onyx | Level 15

Do you mean something like this?:

data want;
  infile cards4 missover;
  input;

  if _INFILE_ =: '*SGT' then
    do until(a=.);
      input;
      a = input(scan(_INFILE_,1," "), ?? best32.);
      b = input(scan(_INFILE_,2," "), ?? best32.);
      if a>. then output;
    end;

cards4;
 **---------------------------- ROCK FLUID -------------------------------
*ROCKFLUID
*RPT
*SGT
      0.005     0.0      0.
      0.040     0.005    0.
      0.080     0.013    0.
      0.120     0.026    0.
      0.160     0.040    0.
      0.200     0.058    0.
      0.240     0.078    0.
      0.280     0.100    0.
      0.320     0.126    0.
      0.360     0.156    0.
      0.400     0.187    0.
      0.440     0.222    0.
      0.480     0.260    0.
      0.520     0.300    0.
      0.560     0.348    0.
      0.600     0.400    0.
      0.640     0.450    0.
      0.680     0.505    0.
      0.720     0.562    0.
      0.760     0.620    0.
      0.800     0.680    0.
      0.840     0.740    0.
*SWT
      0.160     0.0      0.
      0.200     0.002    0.
      0.240     0.010    0.
      0.280     0.020    0.
      0.320     0.033    0.
      0.360     0.049    0.
      0.400     0.066    0.
      0.440     0.090    0.
      0.480     0.119    0.
      0.520     0.150    0.
      0.560     0.186    0.
      0.600     0.227    0.
      0.640     0.277    0.
      0.680     0.330    0.
      0.720     0.390    0.
      0.760     0.462    0.
      0.800     0.540    0.
      0.840     0.620    0.
      0.880     0.710    0.
      0.920     0.800    0.
      0.960     0.900    0.
      0.995     1.0      0.
**-------------------------------- INITIAL CONDITION --------
*INITIAL
*VERTICAL *DEPTH_AVE *WATER_GAS
*REFPRES  3550.0
;;;;
run;

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



ngottala
SAS Employee
Thank you. Yes, this is the output i needed
Ksharp
Super User
%let key=  *SGT ;

data want;
  infile 'c:\temp\k1r1.txt' termstr=lf length=len;
  input want $varying400. len;
  retain found .;
  if want =: "&key." then found=1;
  if first(want)='*' and  want ne: "&key." then found=0;
  if found;
run;
ngottala
SAS Employee
Thank you for your solution. Yes, that's the output i needed

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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
  • 4 replies
  • 776 views
  • 0 likes
  • 3 in conversation