×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Use macro variable to assign a variable value

Use macro variable to assign a variable value

Use macro variable to assign a variable value

(OP)
I have a dataset whose structure is similar to:

person   obs colour
Dave     1   red
Dave     1   green
Dave     1   blue
Mary     1   blue
Mary     1   red
Mary     2   green

There could be anywhere between 1 and 13  colours for each person-obs combination

i would like to transpose this to one row per person-obs combination with column names matching the colour variable value and a flag to indicate which colours matched the person-observation combo:

Person   Obs   Red  Blue  Green
Dave     1     1    1     1
Mary     1     1    1     0
Mary     2     0    0     1


I can use the retain statement to generate and initialise my colour column names, and then loop through a group of person-obs combinations until i hit last.obs. I can read in the value of the variable colour into a macro variable within a datastep, and can use the resolve function to get this 'value', but i cannot find a way to use the string value of this macro variable to assign a '1' flag to the column name that corresponds to this string value:

call symput('mac_colour', colour);
colourvar = compress(resolve('&mac_colour'));

How do i use the string value of colourvar to set a column name equal to the value of colourvar to 1?

Any method i try doesn't like have a function on the left of an assign statement.

Any ideas? Cheers in advance

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close