BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Nasser_DRMCP
Lapis Lazuli | Level 10

Hello,

 

I have a data set that holds 20 columns classe_1, classe_2, classe_3....classe_20.

possibles classe values : 5, 4, 17, C, B2.

i would like to concatenate all columns that begins with class_

thanks for your help in advance

regards

Nasser

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

From the documentation cats and related concatenation functions will default to a length of 200 characters if not explicitly assigned prior to use. So if your 20 class variables have more than 10 characters each you may need to assign a maximum expected length.

 

Also if you want a space or comma between the classes then use Catx

 

var= catx(',', of class: );

or (space between)

var= catx(' ', of class: );

or (and especially if people are to read this result) a comma and a space

var= catx(', ', of class: );

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20
var=cats(of class_:);
ballardw
Super User

From the documentation cats and related concatenation functions will default to a length of 200 characters if not explicitly assigned prior to use. So if your 20 class variables have more than 10 characters each you may need to assign a maximum expected length.

 

Also if you want a space or comma between the classes then use Catx

 

var= catx(',', of class: );

or (space between)

var= catx(' ', of class: );

or (and especially if people are to read this result) a comma and a space

var= catx(', ', of class: );

Nasser_DRMCP
Lapis Lazuli | Level 10

hello novinosrin

 

thanks for your help. but I get this message "The CATS function call does not have enough arguments" by attempting your suggestion.

however it works with

var= catx('', of class: );

Astounding
PROC Star

That's because your actual variable names are classe_1, classe_2, etc., not class_1, class_2.  This would fix it (but would still have the issue of possibly removing too many blanks):

 

var = cats(of classe_: );

emrancaan
Obsidian | Level 7

You can use this macro,  just add you DATASET NAME and LIBRARY NAME into it.

 

%macro getvars(lib,dsn);
    %global vlist;
    proc sql;
        select name into :vlist separated by ' '
        from dictionary.columns
        where memname = upcase("&dsn")
		and libname =upcase("&lib")
		and name like 'class%'
    ;quit;
%mend;

%getvars(LIBRARY,DATASET);

%Put &vlist

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 5 replies
  • 5858 views
  • 4 likes
  • 5 in conversation