Question:- I would like to use Macro and want to create a new variable (i am trying to create age variable form birthday variable in dataset(excel file)) . I try to write this code. Can anyone explain what is wrong in this code and why i am not able to use Macro this way.
1.code 1
data fs;
set bb;
call symput('var',age(int((Today()-birthday)/365.25)));
run;
2. code2
data fs;
set bb;
call symput('var',age(int((&sysdate-birthday)/365.25)));
run;
@unnati wrote:
Question:- I would like to use Macro and want to create a new variable (i am trying to create age variable form birthday variable in dataset(excel file)) . I try to write this code.
Can anyone explain what is wrong in this code and why i am not able to use Macro this way.
Excel files do not show us the actual values in your data variables in the SAS data set.
Better is to post example data as a data step. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.
Why do you want a macro variable? How is it going to be used?
If you want an Age attached to each record in your data there is no reason to use a macro at all.
You can get the age given two SAS date values using
Age= yrdif(birthday,today(),'AGE'); which will yield a number of years and a decimal portion.
If you only want the calendar years then
Age = floor(yrdif(birthday,today,'AGE'));
which will discard the decimal portion.
What are you trying to do?
There's no AGE function so your reference there is incorrect.
@unnati wrote:
Question:- I would like to use Macro and want to create a new variable (i am trying to create age variable form birthday variable in dataset(excel file)) . I try to write this code. Can anyone explain what is wrong in this code and why i am not able to use Macro this way.
1.code 1 data fs; set bb; call symput('var',age(int((Today()-birthday)/365.25))); run; 2. code2 data fs; set bb; call symput('var',age(int((&sysdate-birthday)/365.25))); run;
@unnati wrote:
Question:- I would like to use Macro and want to create a new variable (i am trying to create age variable form birthday variable in dataset(excel file)) . I try to write this code.
Can anyone explain what is wrong in this code and why i am not able to use Macro this way.
Excel files do not show us the actual values in your data variables in the SAS data set.
Better is to post example data as a data step. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.
Why do you want a macro variable? How is it going to be used?
If you want an Age attached to each record in your data there is no reason to use a macro at all.
You can get the age given two SAS date values using
Age= yrdif(birthday,today(),'AGE'); which will yield a number of years and a decimal portion.
If you only want the calendar years then
Age = floor(yrdif(birthday,today,'AGE'));
which will discard the decimal portion.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.