Type : CREATION_INTERNE
Data (text files) are generated on the fly by DATA _NULL_ steps using the FILE instruction.
| 1 | %let test1="&sasjswork/file.txt"; |
| 2 | %let str=replace/me; |
| 3 | %let rep=with/this; |
| 4 | DATA _null_; |
| 5 | file &test1; |
| 6 | put 'blahblah'; |
| 7 | put "blahblah&str.blah"; |
| 8 | put 'blahblahblah'; |
| 9 | RUN; |
| 1 | %mp_assertscope(SNAPSHOT) |
| 2 | %mp_replace(&test1, findvar=str, replacevar=rep) |
| 3 | %mp_assertscope(COMPARE) |
| 1 | DATA _null_; |
| 2 | INFILE &test1; |
| 3 | INPUT; |
| 4 | IF _n_=2 THEN call symputx('test1result',_infile_); |
| 5 | RUN; |
| 6 | |
| 7 | %mp_assert( |
| 8 | iftrue=("&test1result" = "blahblah&rep.blah"), |
| 9 | desc=Checking first replace, |
| 10 | outds=work.test_results |
| 11 | ) |
| 1 | %let test2="&sasjswork/file2.txt"; |
| 2 | %let str=%str(replacewith trailing spaces ); |
| 3 | %let rep=%str( with more spaces ); |
| 4 | DATA _null_; |
| 5 | file &test2 lrecl=500; |
| 6 | put 'blahblah'; |
| 7 | put "blahblah&str.blah&str. replace &str.X"; |
| 8 | put "blahbreplacewith&str.spacesahblah"; |
| 9 | RUN; |
| 1 | %mp_replace(&test2, findvar=str, replacevar=rep) |
| 2 | |
| 3 | DATA _null_; |
| 4 | INFILE &test2 lrecl=500; |
| 5 | INPUT; |
| 6 | IF _n_=2 THEN call symputx('test2resulta',_infile_); |
| 7 | IF _n_=3 THEN call symputx('test2resultb',_infile_); |
| 8 | RUN; |
| 9 | |
| 10 | %mp_assert( |
| 11 | iftrue=("&test2resulta" = "blahblah&rep.blah&rep. replace &rep.X"), |
| 12 | desc=Checking second replace 2nd row, |
| 13 | outds=work.test_results |
| 14 | ) |
| 1 | %let test3="&sasjswork/file3.txt"; |
| 2 | %let str=%str(replace.string.with.dots ); |
| 3 | %let rep=%str( more.dots); |
| 4 | DATA _null_; |
| 5 | file &test3 lrecl=500; |
| 6 | put 'blahblah'; |
| 7 | put "blahblah&str.blah&str. replace &str.X"; |
| 8 | put "blahbreplacewith&str.spacesahblah"; |
| 9 | RUN; |
| 1 | %mp_replace(&test3, findvar=str, replacevar=rep) |
| 2 | |
| 3 | DATA _null_; |
| 4 | INFILE &test3 lrecl=500; |
| 5 | INPUT; |
| 6 | IF _n_=2 THEN call symputx('test3resulta',_infile_); |
| 7 | IF _n_=3 THEN call symputx('test3resultb',_infile_); |
| 8 | RUN; |
| 9 | |
| 10 | %mp_assert( |
| 11 | iftrue=("&test3resulta" = "blahblah&rep.blah&rep. replace &rep.X"), |
| 12 | desc=Checking third replace 2nd row (dots), |
| 13 | outds=work.test_results |
| 14 | ) |