09-05-2014 12:16 PM
Does anyone know if there is a way (ie SAS command) to insert a new variable between existing SAS variables in a dataset?
For example I have the following dataset......
......and I want to end up with the dataset below.
Name Sex Age
Tom M 10
John M 18
Jill F 23
Chris M 25
Don M 31
09-05-2014 12:19 PM
if you have another dataset with name and sex variables , then you can use the merge statement to combine the age dataset with gender dataset by name variable and you can get the three variables in a single dataset.
merge age gender;
09-05-2014 12:35 PM
09-05-2014 12:57 PM
There is no relationship per se. I have a dataset that already contains the Name and Age variables and I am trying to create/generate a new variable (Sex) between the two existing ones. I was hoping that there is a way to do this in SAS, similar to how you can insert a new column in Excel and fill it in with values.
I know how to create a new variable at the end of the variables in my existing dataset, but I was hoping to be able to create it betweent the two existing ones.
09-05-2014 01:19 PM
Thank you so much. I created a scenario to myself as per your explanation. Please adjust it your needs. What stat@sas provided works great in the situation.
INPUT NAME $ AGE;
RETAIN NAME SEX AGE;
IF INDEX(NAME,'O') THEN
Need further help from the community? Please ask a new question.