BookmarkSubscribeRSS Feed
walska
Calcite | Level 5

I'm trying to concatenate all variables in a dataset into a singular variable, however some of the input variables contain only zeros. When using the CAT procedure these zero filled variables are removed. However, I need to retain these zeroes within the final variable. Additionally, I do not want to put any delimiters within this variable.

5 REPLIES 5
Shmuel
Garnet | Level 18

Are all the variables type defined as alphanumeric or are some of them numeric.

Numeric variables are usually displayed with leading zeros suppression.

In order not to suppress leading zeroes use format z9,  where 9 define the length of desired variable for concatenation:

      assume x='ABC';   /* alphanumeric */

                     y = 25;     /* numeric */

       result = cat(x, put(y,z5));      /* = ABC00025 */

walska
Calcite | Level 5
Hi Shmuel, all the variables are numeric.
Reeza
Super User

Zeroes wouldn't be removed, but missing would be. Verify if the data is missing or 0. 

 

If missing(variable) then ...

Shmuel
Garnet | Level 18

What is the use of concatenating numeric variables ?

 

You still need to decide how long is each variable.

       v1 = 12345;  v2=33;   v3=7;

       v1=  6789;    v2=120;  v3=99;

 

      result = put(v1,z6.) || put(v2,z4.) || put(v3,z2.);

ballardw
Super User

A very basic item in requesting suggestions is to provide an example of your starting data and the desired result for that data. It need not have as many variables or observations as you have but enough to show an example and clarify your description. Without concrete values we're guessing somewhat as to what your result would be.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1121 views
  • 0 likes
  • 4 in conversation