DATA Step, Macro, Functions and more

Loop inside Macro

Accepted Solution Solved
Reply
Contributor
Posts: 41
Accepted Solution

Loop inside Macro

Dear all,

I am trying to change the format from character to numeric of a list of variables in my dataset. I've written the code but it seems that it applies only to the last variable. So I cannot see all new numeric variables in my dataset. Can anyone help me? The code is attached. 

 

%macro numeric(var);
data mydata.fhsim_n;
set mydata.fhsim;
&var._n=input(&var ,8.);
run;
%mend numeric;
%numeric(Account_No); run;
%numeric(Acct_Status); run;


Accepted Solutions
Solution
‎03-01-2017 04:52 PM
PROC Star
Posts: 7,468

Re: Loop inside Macro

I wouldn't use a macro for it but, since you already wrote it, just make a copy of your original file and then change your macro to work on that file.

 

/* first run a data step like*/

data mydata.fhsim_n;
  set mydata.fhsim;
run;

/*then change your macro to*/
%macro numeric(var);
  data mydata.fhsim_n;
    set mydata.fhsim_n;
    &var._n=input(&var ,8.);
  run;
%mend numeric;

%numeric(Account_No); run;
%numeric(Acct_Status); run;

Art, CEO, AnalystFinder.com

View solution in original post


All Replies
PROC Star
Posts: 7,468

Re: Loop inside Macro

You're rewriting the new file each time you run the macro. 

 

Art, CEO, AnalystFinder.com

 

Contributor
Posts: 41

Re: Loop inside Macro

What should I then do to keep all variables in?
Solution
‎03-01-2017 04:52 PM
PROC Star
Posts: 7,468

Re: Loop inside Macro

I wouldn't use a macro for it but, since you already wrote it, just make a copy of your original file and then change your macro to work on that file.

 

/* first run a data step like*/

data mydata.fhsim_n;
  set mydata.fhsim;
run;

/*then change your macro to*/
%macro numeric(var);
  data mydata.fhsim_n;
    set mydata.fhsim_n;
    &var._n=input(&var ,8.);
  run;
%mend numeric;

%numeric(Account_No); run;
%numeric(Acct_Status); run;

Art, CEO, AnalystFinder.com

Contributor
Posts: 41

Re: Loop inside Macro

Thank you very much! Let me try!
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 138 views
  • 0 likes
  • 2 in conversation