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

I have a table with variable names (string values) in column form that come from a user input.  There is always 1 column with the header called "Name" but the number of rows in the column is undefined (based on user input, the variable list is currently called by the macro &THRES_VARS).

Example Data:

Name

Variable1

Variable2

Variable3

I need the resulting output to be a 1 column 1 row table that looks like this:

Variable1+Variable2+Variable3

Does anyone know how to produce code/macro to produce the output?

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

assuming you literally want it separated by "+"

Here's one way via code.  You can change the delimiter as you like as well.  Make sure the initial length of the variable is long enough to hold the resulting string.

firstobs is set to 2 so that the name is not included.

data want;

length variable $512;

set have (firstobs=2) end=eof;

retain variable;

variable=catx("+", variable, your_variable);

if eof then output;

run;

View solution in original post

2 REPLIES 2
Reeza
Super User

assuming you literally want it separated by "+"

Here's one way via code.  You can change the delimiter as you like as well.  Make sure the initial length of the variable is long enough to hold the resulting string.

firstobs is set to 2 so that the name is not included.

data want;

length variable $512;

set have (firstobs=2) end=eof;

retain variable;

variable=catx("+", variable, your_variable);

if eof then output;

run;

arogers
Calcite | Level 5

That is exactly what I needed.  Thanks so much.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 769 views
  • 0 likes
  • 2 in conversation