Desktop productivity for business analysts and programmers

changing place for variable from one place to another place

Accepted Solution Solved
Reply
Regular Contributor
Posts: 220
Accepted Solution

changing place for variable from one place to another place

Hi all, i have one variable name 'empsal' in middle of dataset (have around 9000 variable and 'empsal' is there in between) and i wants to bring it as second or first variable/column,- how can i do that?

plz help

thanks.


Accepted Solutions
Solution
‎03-21-2013 03:06 PM
Super User
Posts: 3,237

Re: changing place for variable from one place to another place

Just add an ATTRIB statement before you read your dataset to make it first:

data new;

  attrib empsal length = 8;

  set old;

run;

If you want it second then add the variable you want first before empsal in the ATTRIB statement.

View solution in original post


All Replies
Solution
‎03-21-2013 03:06 PM
Super User
Posts: 3,237

Re: changing place for variable from one place to another place

Just add an ATTRIB statement before you read your dataset to make it first:

data new;

  attrib empsal length = 8;

  set old;

run;

If you want it second then add the variable you want first before empsal in the ATTRIB statement.

Regular Contributor
Posts: 220

Re: changing place for variable from one place to another place

worked prefectly - Thanks SASKIWI.

one quick q, i have 'empsal' variable as employee name and salary,

e,g;

empsal

harstein1 150000

lawson2 120000

kumar3 50000

i want to keep salary only (150000, 120000, 50000) and remove (harstein1, lawson2, kumar3).

result would be;

empsal

150000

120000

50000

can you plz tell me how code should look like?

Thanks!

Super User
Posts: 3,237

Re: changing place for variable from one place to another place

If it's consistently always two words then you could do it this way:

empsal = scan(empsal,2);

However wouldn't it be better to store empsal as a number:

empsal_num = input(scan(empsal,2), best12.);

🔒 This topic is solved and locked.

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

Discussion stats
  • 3 replies
  • 175 views
  • 0 likes
  • 2 in conversation