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

I've tried doing this in so many dirty ways, I figured it's time to ask for help.

 

I have 375 x variables that go x1-x375 and and one trial variable that counts up 1-180 in a single column. Each trial can have a different number of x's, anywhere from x1-x25 as the shortest all the way to x1-x375 as the longest. Yet every trial has x1-x375. The x's that don't have data are missing or a .

 

Trial X1 X2 X3 X4 X5 . . . . . . X374 X375

  1    22  25 46 48  79                 .       .

 

I'm just trying to concatenate all the X's together. I tried:

 

x_cat = catx(",", of x:);

 

And it keeps returning an error "Invalid numeric data". I even tried filling in every . with another value then converting it to a character and I still get the same issue. Any help would be very much appreciated.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@Reeza wrote:
Check that all your X are the same variable type. If you have other variables that start with X that may cause an issue. You can try listing it explicitly otherwise.

x_cat = catx(", ", of x1-x375);

I think it ignores missing by default anyways.

If the variables are numeric and the current MISSING option has character other than a blank you would get the missing character in the string result:

data junk;
  x1=1;x2=.;x3=3;
  z= catx(',',of x:);
run;

If the current option missing=' '; then the resolved blank is ignored:

option missing=' ';
data junk;
  x1=1;x2=.;x3=3;
  z= catx(',',of x:);
run;

If the variable with the missing value is character then it is in effect ignored.

 

I suspect debugging this variable with a mix of numeric and character values with an irregular pattern to missingness might be entertaining.

View solution in original post

10 REPLIES 10
PaigeMiller
Diamond | Level 26

CATX shouldn't care if the value of Xn is numeric or character.

 

Thus, I assume that X_CAT is defined as numeric, and you can't concatenate all those numbers into a long text string and assign it to the numeric variable X_CAT. So make sure X_CAT is a character variable.

 

Side question for my own understanding and possible future use: What possible use is there of such a long character string created by

catx(",", of x:)

 

--
Paige Miller
davidsmarch
Calcite | Level 5

Thanks, Paige, that was indeed part of the issue! I tried everything, but I indeed needed to define the x_cat as a character before the concatenate step. 

 

However, there is now the issue that it is not seeing the . as missing, but instead is doing:

 

42,52,118,165,206,239,247,249,267,270,272,274,276,278,278,278,281,281,289,289,289,289,289,289,289,289,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.

 

I thought the CATX ignored blanks. All the x variables are numerical, so I'm not sure why it's seeing these as data points. 

 

To your question about the utility of such long strings, this is a particular format of mouse-tracking data for an R package called mouse-trap that requires every X- and Y- path within a single trial to be concatenated into a single cell. 

Reeza
Super User
Check that all your X are the same variable type. If you have other variables that start with X that may cause an issue. You can try listing it explicitly otherwise.

x_cat = catx(", ", of x1-x375);

I think it ignores missing by default anyways.
novinosrin
Tourmaline | Level 20

Good evening @Reeza  CATX will have no issues with "Check that all your X are the same variable type"  as the doctor @PaigeMiller  pointed out as I have anointed him as our doctor with perfect diagnosis almost at all times. 🙂 So in essence CATX will convert the num values to char using BEST format and will not write conversion NOTES in the log. 

 

@davidsmarch   All you need is a LENGTH statement  at compile time for the compiler to create a CHAR var named X_cat like for example

length x_cat $200;

 

If this works, you should mark the doctor miller's solution as correct 

 

EDIT: Reeza, you have a point. My apologies, I didn't see you were referring to the sequence of Xs. Sorry again!

 

 

 

 

ballardw
Super User

@Reeza wrote:
Check that all your X are the same variable type. If you have other variables that start with X that may cause an issue. You can try listing it explicitly otherwise.

x_cat = catx(", ", of x1-x375);

I think it ignores missing by default anyways.

If the variables are numeric and the current MISSING option has character other than a blank you would get the missing character in the string result:

data junk;
  x1=1;x2=.;x3=3;
  z= catx(',',of x:);
run;

If the current option missing=' '; then the resolved blank is ignored:

option missing=' ';
data junk;
  x1=1;x2=.;x3=3;
  z= catx(',',of x:);
run;

If the variable with the missing value is character then it is in effect ignored.

 

I suspect debugging this variable with a mix of numeric and character values with an irregular pattern to missingness might be entertaining.

davidsmarch
Calcite | Level 5

Sorry, I just saw this option missing solution, that solves the problem of the . If i could set both of these as solutions I would. Thanks fellas!

Reeza
Super User
This actually depends on how you specify the lists as well.
novinosrin
Tourmaline | Level 20

 @davidsmarch  Here is a test:

 


data have;
call streaminit(123);
array x(275);
do _n_=1 to dim(x);
 x(_n_)=int(ranuni(0)*100);
end;
run;

data want;
set have;
length x_cat $32767;
x_cat=catx(',',of x:);
run;


proc print noobs;
run;


x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44 x45 x46 x47 x48 x49 x50 x51 x52 x53 x54 x55 x56 x57 x58 x59 x60 x61 x62 x63 x64 x65 x66 x67 x68 x69 x70 x71 x72 x73 x74 x75 x76 x77 x78 x79 x80 x81 x82 x83 x84 x85 x86 x87 x88 x89 x90 x91 x92 x93 x94 x95 x96 x97 x98 x99 x100 x101 x102 x103 x104 x105 x106 x107 x108 x109 x110 x111 x112 x113 x114 x115 x116 x117 x118 x119 x120 x121 x122 x123 x124 x125 x126 x127 x128 x129 x130 x131 x132 x133 x134 x135 x136 x137 x138 x139 x140 x141 x142 x143 x144 x145 x146 x147 x148 x149 x150 x151 x152 x153 x154 x155 x156 x157 x158 x159 x160 x161 x162 x163 x164 x165 x166 x167 x168 x169 x170 x171 x172 x173 x174 x175 x176 x177 x178 x179 x180 x181 x182 x183 x184 x185 x186 x187 x188 x189 x190 x191 x192 x193 x194 x195 x196 x197 x198 x199 x200 x201 x202 x203 x204 x205 x206 x207 x208 x209 x210 x211 x212 x213 x214 x215 x216 x217 x218 x219 x220 x221 x222 x223 x224 x225 x226 x227 x228 x229 x230 x231 x232 x233 x234 x235 x236 x237 x238 x239 x240 x241 x242 x243 x244 x245 x246 x247 x248 x249 x250 x251 x252 x253 x254 x255 x256 x257 x258 x259 x260 x261 x262 x263 x264 x265 x266 x267 x268 x269 x270 x271 x272 x273 x274 x275 x_cat 
8 15 29 1 10 98 78 47 64 92 41 25 84 72 84 75 65 62 48 70 22 51 95 82 83 25 23 31 85 37 43 24 89 48 45 11 88 88 37 54 39 2 38 50 33 58 25 75 66 9 79 12 4 87 59 11 87 24 56 84 34 77 35 3 98 27 92 77 9 39 45 64 18 40 77 22 70 3 7 50 31 91 19 45 13 88 50 94 46 15 74 60 79 76 52 95 23 60 47 35 29 94 34 32 21 86 76 58 1 50 37 17 3 31 27 53 86 33 95 75 7 69 88 63 91 95 89 29 59 79 93 46 1 61 6 38 61 48 55 97 81 38 84 29 65 66 32 52 15 96 74 25 75 29 21 89 8 42 39 42 32 82 12 28 69 74 80 28 35 83 16 95 96 50 54 90 21 78 57 82 83 80 65 22 68 77 25 73 80 15 35 41 33 81 79 98 50 40 58 12 27 2 99 86 17 50 81 0 98 93 70 54 87 58 40 81 83 5 91 22 68 92 19 80 24 55 1 65 70 12 71 72 62 66 92 18 92 35 72 56 56 74 27 96 45 38 16 97 20 81 92 92 61 31 90 89 62 46 32 23 99 62 93 60 70 80 95 65 44 4 90 19 43 56 31 8,15,29,1,10,98,78,47,64,92,41,25,84,72,84,75,65,62,48,70,22,51,95,82,83,25,23,31,85,37,43,24,89,48,45,11,88,88,37,54,39,2,38,50,33,58,25,75,66,9,79,12,4,87,59,11,87,24,56,84,34,77,35,3,98,27,92,77,9,39,45,64,18,40,77,22,70,3,7,50,31,91,19,45,13,88,50,94,46,15,74,60,79,76,52,95,23,60,47,35,29,94,34,32,21,86,76,58,1,50,37,17,3,31,27,53,86,33,95,75,7,69,88,63,91,95,89,29,59,79,93,46,1,61,6,38,61,48,55,97,81,38,84,29,65,66,32,52,15,96,74,25,75,29,21,89,8,42,39,42,32,82,12,28,69,74,80,28,35,83,16,95,96,50,54,90,21,78,57,82,83,80,65,22,68,77,25,73,80,15,35,41,33,81,79,98,50,40,58,12,27,2,99,86,17,50,81,0,98,93,70,54,87,58,40,81,83,5,91,22,68,92,19,80,24,55,1,65,70,12,71,72,62,66,92,18,92,35,72,56,56,74,27,96,45,38,16,97,20,81,92,92,61,31,90,89,62,46,32,23,99,62,93,60,70,80,95,65,44,4,90,19,43,56,31 
Astounding
PROC Star
Just a side note, not critical to a solution:

The list of variables included in x: includes x_cat, in addition to x1-x375.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 10 replies
  • 1808 views
  • 3 likes
  • 7 in conversation