DATA Step, Macro, Functions and more

Array

Reply
Occasional Contributor
Posts: 15

Array

Hi,

In one of my data set I have 37 numeric columns out which, one numeric column is in date format.

My requirement was to replace all the null values(.) from the data set with zeros and I had used the following array

data liab_asset1;
set liab_asset;
array v(*) _numeric_;
do i = 1 to dim(v);
if v(i) = . then v(i) = 0;
end;
drop i;
run;


But this statement replaces all the null fields from the date field also. If i dont want to do any action on the date field how should I write the query..?

Please help..!!
Respected Advisor
Posts: 4,173

Re: Array

Posted in reply to syam_india_kochi
From a performance point of view there will be better solutions but below approach means only small changes to your existing code.
Make sure to write the name of the var to exclude in capital letters.


data liab_asset1;
set liab_asset;
array v(*) _numeric_;
do i = 1 to dim(v);
if vname(v(i)) ne '' and v(i) = .
then v(i) = 0;
end;
drop i;
run;


SAS knows only 2 datatypes: Numeric and character. A SAS date is stored as a number in a numeric variable - and this number then "interpreted" by applying an appropriate date format.

HTH
Patrick
Occasional Contributor
Posts: 15

Re: Array

Thank you very much Patrick...
Occasional Contributor
Posts: 15

Re: Array

Thank you very much Patrick...
Super Contributor
Super Contributor
Posts: 3,174

Re: Array

Posted in reply to syam_india_kochi
As a more direct alternative, consider using the VFORMAT function instead, presuming your SAS DATE variable has a SAS date-type output FORMAT associated.

Scott Barry
SBBWorks, Inc.
Ask a Question
Discussion stats
  • 4 replies
  • 163 views
  • 0 likes
  • 3 in conversation