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

hello SAS experts,

I have about 120 textfiles that I need read a portion of it, an example of the file is attached. My code does not work and need help find the problem.

Thank you.

My Code:

data it.temp_1;                                                                                                                  

infile "C:\CDM\result\CDM_1.out" truncover;                                                                                               

input test 9. @;

if test="BASED ON ESTIMATED POSTERIOR PROBABILITIES" then do;                                                                                                

input  /  @3 class                                                                                                             

          @17 popul                                                                                                                 

          @37 proportion;                                                                                                       

output;                                                                                                                               

stop;                                                                                                                                 

end;                                                                                                                                   

drop test;                                                                                                                             

run; 

The portion I need to read:

FINAL CLASS COUNTS AND PROPORTIONS FOR THE LATENT CLASS PATTERNS

BASED ON ESTIMATED POSTERIOR PROBABILITIES

     Latent

   Classes

       1       3689.92934          0.36899

       2        468.37301          0.04684

       3        269.98721          0.02700

       4        309.98844          0.03100

       5        685.71226          0.06857

       6        428.21773          0.04282

       7        528.04662          0.05280

       8       3619.74539          0.36197

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

I think that the following will achieve what you want:

data it.temp_1;

  infile "C:\CDM\result\CDM_1.out"  truncover;

  input;

  if index(upcase(_infile_),

   "BASED ON ESTIMATED POSTERIOR PROBABILITIES")

   then do;

    input;input;input;input;

    do until (missing(class));

      input class popul proportion;

      if not missing(class) then output;

    end;

  end;

run;

View solution in original post

8 REPLIES 8
art297
Opal | Level 21

I think that the following will achieve what you want:

data it.temp_1;

  infile "C:\CDM\result\CDM_1.out"  truncover;

  input;

  if index(upcase(_infile_),

   "BASED ON ESTIMATED POSTERIOR PROBABILITIES")

   then do;

    input;input;input;input;

    do until (missing(class));

      input class popul proportion;

      if not missing(class) then output;

    end;

  end;

run;

R_A_G_
Calcite | Level 5

Thank you art297, it does work well, but may I ask what do these codes do:

1) if index(upcase(_infile_),

2) input;input;input;input; (isn't only 3 variables ? then why 4 inputs?)

3)    do until (missing(class));

Thanks again

art297
Opal | Level 21

Sure you can ask:

1) if index is simply using the index function to see if a text string exists in a variable

2) the four input statements simply skip four records

3) do until (missing(class)) .. as I understood your file, and request, you only wanted the data that existed from the time a record contained the string "BASED ON ESTIMATED POSTERIOR PROBABILITIES", then needed to skip four records, then, finally read all of the remaining records until a value for class wasn't found.  That is what this statement was intended to accomplish.

R_A_G_
Calcite | Level 5

thank you very much. This helps plenty

RG

MikeZdeb
Rhodochrosite | Level 12

Hi ... if the files all have this structure, here's another idea ...

data x;

infile 'z:\cdm_1.out';

input @ "FINAL CLASS COUNTS AND PROPORTIONS FOR THE LATENT CLASS PATTERNS" ////;

do _n_=1 to 8;

   input class popul proportion;

   output;

end;

stop;

run;

R_A_G_
Calcite | Level 5

Thanks for the code, the code is definitely simpler but unfortunately doesn't work on my file, I tried it for one of the files but doesn't read the numbers, I do not know why.

thanks anyway

R

art297
Opal | Level 21

Did you change the directory letter which Mike had as "z:\"?  His code worked on my system.

MikeZdeb
Rhodochrosite | Level 12

Hi ... in addition to making sure that the FOLDER is correct (as Art pointefd out), the SPACING and CASE of the text in the INPUT statement must match that in the data file.  Did you try just cut/paste/run the posted code?  Like Art said, it does work with the file you posted.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 8 replies
  • 958 views
  • 3 likes
  • 3 in conversation