Hello,
I have a program that creates a csv file. When I open this csv file in ultra edit, I get a hex value of '00' in certain columns. (see image below), that is '.....'
I want to change these to blanks (hex value 20). How can I make this conversion only on these specific hex values?
%DS2CSV is just going to write the values in the dataset.
To change one character to another you can use the TRANSLATE() function.
SO if the binary zeros are in the variable XXX you could use a data step like this to create a new dataset with the zeros replaced with spaces.
data want;
set have;
xxx=translate(xxx,' ','00'x);
run;
If you have such bytes in multiple variables then use an array:
data want;
set have;
array __c _character_;
do over __c;
__c=translate(__c,' ','00'x);
end;
run;
Once you have a dataset without the binary zeros then you can write a CSV file that will not have binary zeros.
We can only be of help if we see the code which is creating this file. If display formats are not part of the export code, also show the format assigned to that particular variable in the dataset.
BTW, anybody with excess time can reconstruct your blacked-out strings from the hex codes 😉
Hello,
Thank you for your reply. Please find the code below:
%ds2csv
(data = work.SOLUTION2, runmode = b, csvfile= &RacineRun.&RacineIV./fichiers/solution_2.csv, sepchar = 3B, colhead=y, formats=y, labels=n );
(Corrected)
The macro will export data "as is", so you have these hex zero's in your data. You need to investigate this.
%DS2CSV is just going to write the values in the dataset.
To change one character to another you can use the TRANSLATE() function.
SO if the binary zeros are in the variable XXX you could use a data step like this to create a new dataset with the zeros replaced with spaces.
data want;
set have;
xxx=translate(xxx,' ','00'x);
run;
If you have such bytes in multiple variables then use an array:
data want;
set have;
array __c _character_;
do over __c;
__c=translate(__c,' ','00'x);
end;
run;
Once you have a dataset without the binary zeros then you can write a CSV file that will not have binary zeros.
Thank you so much!!
This worked
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.