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

Hi people

Could anyone help me please?

I need a SAS code to replace the value <br> to \n from a txt file.

The problem is. This txt file is combined in just one single line thus its lrecl contain 223657.

Anybody can help me please?


I've attached the file. I need to change the values "<br>" to "\n." from txt file to the same txt file. That is replace it.


Please, if I could'n t be clear, let me know.

Thanks all.

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

You may be in luck.  I reviewed your file and, from what I could tell, every time there is a less than character (i.e., <), it is followed by 'br><br>' and then two spaces.

If that is correct, it simplifies matters quite a bit.

Another thing I noticed is that the file contains numerous tab characters (i.e., '09'x).  I wasn't sure what you wanted to do with them but, given the following code, they, too, could be easily eliminated.

What the code does is read the file one character at a time.  If it confronts a < character, it simply skips the next seven characters and, in their place, puts in a carriage return and line feed.

Then, after it rewrites the entire file, simply imports it with proc import:

data _NULL_ ;

  FILE "c:\pedacoMarco_new.txt" RECFM=N ;

  infile "c:\pedacoMarco.txt" RECFM=N ;

  input VAR1 $CHAR1. @;

  IF VAR1 eq '<' THEN do;

    do i=1 to 7;

    input VAR1 $CHAR1. @;

    end;

    put '0D'x;

    put '0A'x;

  end;

  else PUT VAR1 $CHAR1. ;

run;

PROC IMPORT OUT= WORK.WANT

            DATAFILE= "C:\pedacoMarco_new.txt"

            DBMS=DLM REPLACE;

     DELIMITER='7C'x;

     GETNAMES=YES;

     DATAROW=2;

RUN;

View solution in original post

2 REPLIES 2
art297
Opal | Level 21

You may be in luck.  I reviewed your file and, from what I could tell, every time there is a less than character (i.e., <), it is followed by 'br><br>' and then two spaces.

If that is correct, it simplifies matters quite a bit.

Another thing I noticed is that the file contains numerous tab characters (i.e., '09'x).  I wasn't sure what you wanted to do with them but, given the following code, they, too, could be easily eliminated.

What the code does is read the file one character at a time.  If it confronts a < character, it simply skips the next seven characters and, in their place, puts in a carriage return and line feed.

Then, after it rewrites the entire file, simply imports it with proc import:

data _NULL_ ;

  FILE "c:\pedacoMarco_new.txt" RECFM=N ;

  infile "c:\pedacoMarco.txt" RECFM=N ;

  input VAR1 $CHAR1. @;

  IF VAR1 eq '<' THEN do;

    do i=1 to 7;

    input VAR1 $CHAR1. @;

    end;

    put '0D'x;

    put '0A'x;

  end;

  else PUT VAR1 $CHAR1. ;

run;

PROC IMPORT OUT= WORK.WANT

            DATAFILE= "C:\pedacoMarco_new.txt"

            DBMS=DLM REPLACE;

     DELIMITER='7C'x;

     GETNAMES=YES;

     DATAROW=2;

RUN;

Augusto
Obsidian | Level 7

Sr Art.

You are definetely genius. Thanks so much it worked perfectly. I just used the String "\n" rather then  put '0D'x;  put '0A'x. Thanks again you always respond my discussion with a great solution.

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!

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
  • 2 replies
  • 4348 views
  • 0 likes
  • 2 in conversation