
%cstutilfindfixextdasciichars( _cstDSName=testdata.ext_ascii, _cstColumnName=stringchars, _cstGeneratedCodeFile=c:/fixascii/findextendedascii.sas);


%macro _cstFixASCII;
********************************************;
********** Initialize libraries **********;
********************************************;
libname TESTDATA "c:\fixascii";
***********************************************************************************;
********** Updating data set testdata.ext_ascii **********;
***********************************************************************************;
%let _cstDSLabel=%cstutilgetattribute(_cstDataSetName=testdata.ext_ascii,
_cstAttribute=LABEL);
%let _cstDSSortVars=%cstutilgetattribute(_cstDataSetName=testdata.ext_ascii,
_cstAttribute=SORTEDBY);
data work.ext_ascii %if %length(&_cstDSLabel)>0 %then (label="&_cstDSLabel"); %else;;
set testdata.ext_ascii ;
if _n_= 1 then do;
stringchars=tranwrd(stringchars,byte(145),byte(39));
end;
if _n_= 2 then do;
stringchars=tranwrd(stringchars,byte(146),byte(39));
end;
if _n_= 3 then do;
stringchars=tranwrd(stringchars,byte(147),byte(34));
end;
if _n_= 4 then do;
stringchars=tranwrd(stringchars,byte(148),byte(34));
end;
run;
%if %length(&_cstDSSortVars)>0 %then
%do;
proc sort data=work.ext_ascii;
by &_cstDSSortVars
run;
%end;
%mend;
%_cstFixASCII;


%cstutilfindfixextdasciichars( _cstDSName=testdata.ext_ascii2, _cstColumnName=stringchars, _cstGeneratedCodeFile=c:/fixascii/findextendedascii2.sas, _cstOutputDS=work._cstProblems2, _cstWriteToLib=testdat2);

c:/fixascii/findextendedascii2.sas file,
which is specified by the _cstGeneratedCodeFile parameter.
%macro _cstFixASCII;
********************************************;
********** Initialize libraries **********;
********************************************;
libname TESTDATA "c:\fixascii";
libname testdat2 "c:\fixascii\copy";
***********************************************************************************;
********** Updating data set testdata.ext_ascii2 **********;
***********************************************************************************;
%let _cstDSLabel=%cstutilgetattribute(_cstDataSetName=testdata.ext_ascii2,
_cstAttribute=LABEL);
%let _cstDSSortVars=%cstutilgetattribute(_cstDataSetName=testdata.ext_ascii2,
_cstAttribute=SORTEDBY);
data testdat2.ext_ascii2 %if %length(&_cstDSLabel)>0 %then (label="&_cstDSLabel"); %else;;
set testdata.ext_ascii2 ;
if _n_= 1 then do;
stringchars=tranwrd(stringchars,byte(145),byte(39));
end;
if _n_= 2 then do;
stringchars=tranwrd(stringchars,byte(146),byte(39));
end;
if _n_= 3 then do;
stringchars=tranwrd(stringchars,byte(147),byte(34));
end;
if _n_= 4 then do;
stringchars=tranwrd(stringchars,byte(148),byte(34));
end;
if _n_= 5 then do;
stringchars=tranwrd(stringchars,byte(159),byte(?));
end;
run;
%if %length(&_cstDSSortVars)>0 %then
%do;
proc sort data=testdat2.ext_ascii2;
by &_cstDSSortVars
run;
%end;
%mend;
%_cstFixASCII;
stringchars=tranwrd(stringchars,byte(159),byte(?))contains the unmapped extended ASCII character. In addition to the ? as a visual cue that a replacement value is needed, a message is written to the SAS log file after the %CSTUTILFINDFIXEXTDASCIICHARS macro is submitted.
*********************************************************************************************** [CSTLOGMESSAGE.CSTUTILFINDFIXEXTDASCIICHARS] WARNING: Unresolved extended ASCII characters are present in the data. Refer to work._cstProblems2 for more information. [CSTLOGMESSAGE.CSTUTILFINDFIXEXTDASCIICHARS] WARNING: These unresolved values need to be updated in the PROC FORMAT statement of this macro. ***********************************************************************************************
stringchars=tranwrd(stringchars,byte(159),byte(?)).)
%cstutilfindfixextdasciichars( _cstDSName=testdata._ALL_, _cstGeneratedCodeFile=c:/fixascii/findfixextendedascii3.sas);
>>>>> >>>>> Starting test for: TESTDATA.EXT_ASCII >>>>> >>>>> Variable List 1='stringchars' 'characters' >>>>> Variable List 2=stringchars characters >>>>> Variable Count= 2 >>>>> >>>>> >>>>> Starting test for: TESTDATA.EXT_ASCII2 >>>>> >>>>> Variable List 1='stringchars' 'characters' >>>>> Variable List 2=stringchars characters >>>>> Variable Count= 2 >>>>>
*********************************************************************************************** [CSTLOGMESSAGE.CSTUTILFINDFIXEXTDASCIICHARS] WARNING: Unresolved extended ASCII characters are present in the data. Refer to work._cstProblems for more information. [CSTLOGMESSAGE.CSTUTILFINDFIXEXTDASCIICHARS] WARNING: These unresolved values need to be updated in the PROC FORMAT statement of this macro. ***********************************************************************************************
%macro _cstFixASCII;
********************************************;
********** Initialize libraries **********;
********************************************;
libname TESTDATA "c:\fixascii";
***********************************************************************************;
********** Updating data set TESTDATA.EXT_ASCII **********;
***********************************************************************************;
%let _cstDSLabel=%cstutilgetattribute(_cstDataSetName=TESTDATA.EXT_ASCII,
_cstAttribute=LABEL);
%let _cstDSSortVars=%cstutilgetattribute(_cstDataSetName=TESTDATA.EXT_ASCII,
_cstAttribute=SORTEDBY);
data work.EXT_ASCII %if %length(&_cstDSLabel)>0 %then (label="&_cstDSLabel"); %else;;
set TESTDATA.EXT_ASCII ;
if _n_= 1 then do;
characters=tranwrd(characters,byte(145),byte(39));
stringchars=tranwrd(stringchars,byte(145),byte(39));
end;
if _n_= 2 then do;
characters=tranwrd(characters,byte(146),byte(39));
stringchars=tranwrd(stringchars,byte(146),byte(39));
end;
if _n_= 3 then do;
characters=tranwrd(characters,byte(147),byte(34));
stringchars=tranwrd(stringchars,byte(147),byte(34));
end;
if _n_= 4 then do;
characters=tranwrd(characters,byte(148),byte(34));
stringchars=tranwrd(stringchars,byte(148),byte(34));
end;
run;
%if %length(&_cstDSSortVars)>0 %then
%do;
proc sort data=work.EXT_ASCII;
by &_cstDSSortVars
run;
%end;
***********************************************************************************;
********** Updating data set TESTDATA.EXT_ASCII2 **********;
***********************************************************************************;
%let _cstDSLabel=%cstutilgetattribute(_cstDataSetName=TESTDATA.EXT_ASCII2,
_cstAttribute=LABEL);
%let _cstDSSortVars=%cstutilgetattribute(_cstDataSetName=TESTDATA.EXT_ASCII2,
_cstAttribute=SORTEDBY);
data work.EXT_ASCII2 %if %length(&_cstDSLabel)>0 %then (label="&_cstDSLabel"); %else;;
set TESTDATA.EXT_ASCII2 ;
if _n_= 1 then do;
characters=tranwrd(characters,byte(145),byte(39));
stringchars=tranwrd(stringchars,byte(145),byte(39));
end;
if _n_= 2 then do;
characters=tranwrd(characters,byte(146),byte(39));
stringchars=tranwrd(stringchars,byte(146),byte(39));
end;
if _n_= 3 then do;
characters=tranwrd(characters,byte(147),byte(34));
stringchars=tranwrd(stringchars,byte(147),byte(34));
end;
if _n_= 4 then do;
characters=tranwrd(characters,byte(148),byte(34));
stringchars=tranwrd(stringchars,byte(148),byte(34));
end;
if _n_= 5 then do;
characters=tranwrd(characters,byte(159),byte(?));
stringchars=tranwrd(stringchars,byte(159),byte(?));
end;
run;
%if %length(&_cstDSSortVars)>0 %then
%do;
proc sort data=work.EXT_ASCII2;
by &_cstDSSortVars
run;
%end;
%mend;
characters=tranwrd(characters,byte(159),byte(?));
stringchars=tranwrd(stringchars,byte(159),byte(?));Y and
the _cstGeneratedCodeFile parameter must specify the same file.
N.
This clears the existing data set specified by the _cstOutputDS parameter.
%( _cstDSName=testdata.ext_ascii, _cstGeneratedCodeFile=c:/fixascii/findfixextendedascii4.sas, _cstOutputDS=work.all_asciiProblems, _cstRetainOutputDS=N, _cstFindFix=Find);
Y.
The output data set remains specified as work.all_asciiProblems.
%cstutilfindfixextdasciichars( _cstDSName=testdat2.all_ascii, _cstGeneratedCodeFile=c:/fixascii/findfixextendedascii4.sas, _cstOutputDS=work.all_asciiProblems, _cstRetainOutputDS=Y, _cstFindFix=Find);
Initialize librariesblocks in the code: one for TESTDATA and another for TESTDAT2 (with corresponding output libraries OUT1 and OUT2).
%macro _cstFixASCII;
********************************************;
********** Initialize libraries **********;
********************************************;
libname TESTDAT2 "c:\fixascii\copy";
libname out2 "c:\fixascii\output_two";
***********************************************************************************;
********** Updating data set testdat2.all_ascii **********;
***********************************************************************************;
%let _cstDSLabel=%cstutilgetattribute(_cstDataSetName=testdat2.all_ascii,
_cstAttribute=LABEL);
%let _cstDSSortVars=%cstutilgetattribute(_cstDataSetName=testdat2.all_ascii,
_cstAttribute=SORTEDBY);
data out1.all_ascii %if %length(&_cstDSLabel)>0 %then (label="&_cstDSLabel"); %else;;
set testdat2.all_ascii ;
if _n_= 1 then do;
test_characters=tranwrd(test_characters,byte(9),byte(32));
test_stringchars=tranwrd(test_stringchars,byte(9),byte(32));
end;
…
…
if _n_= 16 then do;
test_characters=tranwrd(test_characters,byte(155),byte(62));
test_stringchars=tranwrd(test_stringchars,byte(155),byte(62));
end;
run;
%if %length(&_cstDSSortVars)>0 %then
%do;
proc sort data=out1.all_ascii;
by &_cstDSSortVars
run;
%end;
********************************************;
********** Initialize libraries **********;
********************************************;
libname TESTDATA "c:\fixascii";
libname out1 "c:\fixascii\output_one";
***********************************************************************************;
********** Updating data set testdata.ext_ascii **********;
***********************************************************************************;
%let _cstDSLabel=%cstutilgetattribute(_cstDataSetName=testdata.ext_ascii,
_cstAttribute=LABEL);
%let _cstDSSortVars=%cstutilgetattribute(_cstDataSetName=testdata.ext_ascii,
_cstAttribute=SORTEDBY);
data out1.ext_ascii %if %length(&_cstDSLabel)>0 %then (label="&_cstDSLabel"); %else;;
set testdata.ext_ascii ;
if _n_= 1 then do;
characters=tranwrd(characters,byte(145),byte(39));
stringchars=tranwrd(stringchars,byte(145),byte(39));
end;
…
…
if _n_= 4 then do;
characters=tranwrd(characters,byte(148),byte(34));
stringchars=tranwrd(stringchars,byte(148),byte(34));
end;
run;
%if %length(&_cstDSSortVars)>0 %then
%do;
proc sort data=out1.ext_ascii;
by &_cstDSSortVars
run;
%end;
%mend;
%_cstFixASCII;
other=MISSING, the value
of the _cstExtFmtOtherValue parameter must be MISSING.
The %CSTUTILFINDFIXEXTDASCIICHARS macro can then act on the missing
value.
other= statement
in the external SAS format, the macro does not detect the missing
value.
other= statement,
the default value is **.
proc format library=work.myformats; value asciifmt 10=32 19=45 20=45 24=39 25=39 28=34 29=34 139=60 145=39 146=39 147=34 148=34 150=45 151=45 155=62 other=MISSING; run; options fmtsearch=(work.myformats); %cstutilfindfixextdasciichars( _cstDSName=testdat2.all_ascii, _cstColumnName=stringchars, _cstExternalFmt=asciifmt, _cstExtFmtOtherValue=MISSING, _cstGeneratedCodeFile=c:/fixascii/findfixextendedascii5.sas, _cstOutputDS=all_cstProblems, _cstRetainOutputDS=N, _cstWriteToLib=work, _cstFindFix=Find );

%macro _cstFixASCII;
********************************************;
********** Initialize libraries **********;
********************************************;
libname TESTDAT2 "c:\fixascii\copy";
***********************************************************************************;
********** Updating data set testdat2.all_ascii **********;
***********************************************************************************;
%let _cstDSLabel=%cstutilgetattribute(_cstDataSetName=testdat2.all_ascii,
_cstAttribute=LABEL);
%let _cstDSSortVars=%cstutilgetattribute(_cstDataSetName=testdat2.all_ascii,
_cstAttribute=SORTEDBY);
data work.all_ascii %if %length(&_cstDSLabel)>0 %then (label="&_cstDSLabel"); %else;;
set testdat2.all_ascii ;
if _n_= 1 then do;
test_stringchars=tranwrd(test_stringchars,byte(9),byte(MISSING));
end;
if _n_= 2 then do;
test_stringchars=tranwrd(test_stringchars,byte(10),byte(32));
end;
if _n_= 3 then do;
...
...
...
test_stringchars=tranwrd(test_stringchars,byte(9),byte(MISSING)); is
the visual cue that an additional mapping is required. This represents
the other= value specified in the external
SAS format.