BookmarkSubscribeRSS Feed
Satora_In
Quartz | Level 8

Dear friends,

I wrote a request only it has a problem that the number of columns is not static but dynamic. Because of this, in my guide they are displayed as a dot and for the catx functions, I have a problem that empty values ​​appear as a dot and a comma (.;.;) in this format. How can I remove empty values to avoid this problem? Thanks for the help.
I have attached my request. Perhaps it can be solved through the condition, help.



data mytable;
set WORK.QUERY_FOR_TRNSTRANSPOSED;
length result $4100;
result = catx(';',Столбец1,Столбец2,Столбец3,Столбец4,Столбец5,Столбец6,Столбец7,Столбец8,Столбец9,Столбец10,Столбец11,Столбец12,Столбец13,Столбец14,Столбец15,
Столбец16,Столбец17,Столбец18,Столбец19,Столбец20,Столбец21,Столбец22,Столбец23,Столбец24,Столбец25,Столбец26,Столбец27,Столбец28,Столбец29,Столбец30,Столбец31,Столбец32,
Столбец33,Столбец34,Столбец35,Столбец36,Столбец37,Столбец38,Столбец39,Столбец40);
format result $char.;
run;

4 REPLIES 4
JosvanderVelden
SAS Super FREQ

You can try with something similar to the code below:

data have;
   input var1 var2 var3 var4 var5;
datalines;
1 . 3 . 5
;
run;

data want(keep=result);
   set have;
   length result $50;
   result = transtrN(catx(';', of var:), ".;", trimn(' '));
   put result=;
run;
Tom
Super User Tom
Super User

Are the variables NUMERIC?

If so change the MISSING option before running the CAT... function.

options missing=' ';
data mytable;
  set WORK.QUERY_FOR_TRNSTRANSPOSED;
  length result $4100;
  result = catx(';', of Столбец1-Столбец40);
run;

PS: Do NOT attach a FORMAT to a plain text variable.  

Amir
PROC Star

Hi,

 

Please clarify:

 

1) If you have an observation with data like:

 

a;b;c;.;d;e

 

Do you want the result to have 2 semicolons (";") next to each other, with or without a space, like:

 

a;b;c;;d;e

 

Or do you want to remove the semicolon too, like:

 

a;b;c;d;e

 

2) If the whole observation looks like:

 

.;.;.;.;.

 

Then do you want to output that observation, if yes, then what should the result look like?

 

If my questions are not clear, then please provide some example data in the form of a data step, showing input data in one data step and required output in another data step.

 

 

Thanks & kind regards,

Amir.

ballardw
Super User

One approach is to set OPTIONS MISSING=' '; before the data step. That way the conversion of missing values (not empty) will be to a space character. The Catx function will trim leading and trailing spaces before concatenation, so there is no period or space in the result for the missing values.

 

options missing=' ';
data mytable;
set WORK.QUERY_FOR_TRNSTRANSPOSED;
length result $4100;
result = catx(';',Столбец1,Столбец2,Столбец3,Столбец4,Столбец5,Столбец6,Столбец7,Столбец8,Столбец9,Столбец10,Столбец11,Столбец12,Столбец13,Столбец14,Столбец15,
Столбец16,Столбец17,Столбец18,Столбец19,Столбец20,Столбец21,Столбец22,Столбец23,Столбец24,Столбец25,Столбец26,Столбец27,Столбец28,Столбец29,Столбец30,Столбец31,Столбец32,
Столбец33,Столбец34,Столбец35,Столбец36,Столбец37,Столбец38,Столбец39,Столбец40);
format result $char.;
run;

/* reset to the default */
options missing='.';

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 482 views
  • 0 likes
  • 5 in conversation