0

I have been working on converting a number of variables in my table to numerical types from characters. I discovered the method to alter one variable and can continue doing so for each variable. However, I wanted to solicit SE because I am having trouble developing a sustainable solution.

How can I edit multiple variables at once in SAS Studio 3.5?

My attempt thus far:

What works:

data work.want(rename=(age_group='Age Group'n));
  set work.import;
  age_group=input('Age Group'n,8.);
  drop 'Age Group'n;
run;

What doesn't work:

data work.want(rename=(age_group='Age Group'n), rename=(dwelling_type='Dwelling Type'n));
      set work.import;
      age_group=input('Age Group'n,8.);
      dwelling_type=input('Dwelling Type'n,8.);
      drop 'Age Group'n, 'Dwelling Type'n;
    run;
1
  • What does this mean: "doesn't work"? Read your log. You want an array to handle multiple conversions. Commented Oct 6, 2016 at 3:31

1 Answer 1

1

For starters your RENAME statement is incorrect. I don't recommend using that type of variable notation though, so I'm going to suggest labels instead. To convert multiple variables use an array. You do have to list them out once at least though, in the array statement.

data work.want;
  set work.import;
  array num_vars(*) age_group dwelling_type;
  array char_vars(*) 'Age Group'n 'Dwelling Type'n;

  do i=1 to dim(num_vars);
       num_vars(i) = input(char_vars(i), 8.);
  end;

  label age_group = 'Age Group'
        dwelling_type = 'Dwelling Type';

run;

If you wanted to do a RENAME as a dataset option, you would do it as follows, no comma's and the keyword rename once.

(rename=(age_group='Age Group'n dwelling_type='Dwelling Type'n));
Sign up to request clarification or add additional context in comments.

2 Comments

This was my first time using SAS and I have been scouring the internet for resources. I have been reading my log, but I don't know how to correct my errors. Thus, I asked for help.
There is an abundance of resources here: support.sas.com/training/tutorial and lexjansen.com - search for your topic of interest.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.