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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.