BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sas_9
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

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

3 REPLIES 3
SASKiwi
PROC Star

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.

sas_9
Obsidian | Level 7

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!

SASKiwi
PROC Star

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.);

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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