SAS Character Comparisons - string

I'm very new at SAS and I have a problem. I have a dataset like this:
Dataset_idchemo
and I want to create a new dummy variable with 0 if Chemo = NonTreated else 1, but idk why I can't, the result is a column with only zeros and a bunch of warnings like " Invalid numeric data, 'Treated' , at line 74 column 13."
My code is:
data new;
set readm;
chemio = 0;
if chemo =: 'Treated' then chemio = 1;
run;
Thanks!
PS: this is my dataset, I don't know if this is the right way to add it here, let me know what's the best way.
There are four columns Oss it's the number of the observation, id, event (0 or 1) and chemo ("Treated", "NonTreated")
Oss id event chemo
1 1 1 Treated
2 1 1 Treated
3 1 0 Treated
4 2 1 NonTreated
5 2 0 NonTreated
6 3 1 NonTreated
7 3 0 NonTreated
8 4 1 Treated
9 4 1 Treated
10 4 1 Treated
11 4 1 Treated
12 4 0 Treated
13 5 1 NonTreated
14 5 0 NonTreated
15 6 1 Treated
16 6 1 Treated
17 6 1 Treated
18 6 0 Treated
19 7 1 Treated
20 7 1 Treated
21 7 1 Treated
22 7 0 Treated
23 8 0 NonTreated
24 9 1 NonTreated
25 9 0 NonTreated
26 10 0 Treated
27 11 1 Treated
28 11 1 Treated
29 11 0 Treated
30 12 0 Treated
31 13 1 NonTreated
32 13 0 NonTreated
33 14 0 Treated
34 15 1 NonTreated
35 15 1 NonTreated
36 15 0 NonTreated
37 16 1 NonTreated
38 16 0 NonTreated
39 17 0 NonTreated
40 18 0 Treated
41 19 0 Treated
42 20 1 Treated
43 20 0 Treated
44 21 1 Treated
45 21 0 Treated
46 22 0 Treated
47 23 1 Treated
48 23 0 Treated
49 24 1 Treated
50 24 0 Treated
51 25 0 Treated
52 26 0 Treated
53 27 0 Treated
54 28 0 NonTreated
55 29 1 Treated
56 29 0 Treated
57 30 0 Treated
58 31 1 Treated
59 31 0 Treated
60 32 1 NonTreated
61 32 1 NonTreated
62 32 0 NonTreated
63 33 1 Treated
64 33 1 Treated
65 33 1 Treated
66 33 0 Treated
67 34 0 Treated
68 35 1 Treated
69 35 0 Treated
70 36 0 Treated
71 37 1 NonTreated
72 37 1 NonTreated
73 37 0 NonTreated
74 38 0 NonTreated
75 39 0 Treated
76 40 1 Treated
77 40 1 Treated
78 40 1 Treated
79 40 1 Treated
80 40 1 Treated
81 40 1 Treated
82 40 0 Treated
83 41 1 Treated
84 41 0 Treated
85 42 1 Treated
86 42 1 Treated
87 42 0 Treated
88 43 1 Treated
89 43 1 Treated
90 43 0 Treated
91 44 1 NonTreated
92 44 0 NonTreated
93 45 0 NonTreated
94 46 0 Treated
95 47 0 NonTreated
96 48 0 NonTreated
97 49 1 NonTreated
98 49 0 NonTreated
99 50 1 NonTreated
100 50 0 NonTreated
101 51 1 NonTreated
102 51 1 NonTreated
103 51 0 NonTreated
104 52 1 NonTreated
105 52 1 NonTreated
106 52 1 NonTreated
107 52 1 NonTreated
108 52 0 NonTreated
109 53 1 Treated
110 53 1 Treated
111 53 0 Treated
112 54 1 NonTreated
113 54 0 NonTreated
114 55 0 Treated
115 56 0 Treated
116 57 0 NonTreated
117 58 0 Treated
118 59 0 Treated
119 60 1 NonTreated
120 60 0 NonTreated
121 61 0 Treated
122 62 0 Treated
123 63 0 Treated
124 64 1 Treated
125 64 0 Treated
126 65 1 Treated
127 65 0 Treated
128 66 0 Treated
129 67 0 NonTreated
130 68 1 NonTreated
131 68 0 NonTreated
132 69 0 Treated
133 70 0 Treated
134 71 1 Treated
135 71 1 Treated
136 71 0 Treated
137 72 0 Treated
138 73 0 Treated
139 74 0 NonTreated
140 75 0 Treated
141 76 1 NonTreated
142 76 1 NonTreated
143 76 0 NonTreated
144 77 0 NonTreated
145 78 1 NonTreated
146 78 1 NonTreated
147 78 1 NonTreated
148 78 1 NonTreated
149 78 0 NonTreated
150 79 1 Treated
151 79 0 Treated
152 80 0 NonTreated
153 81 0 NonTreated
154 82 1 NonTreated
155 82 0 NonTreated
156 83 1 Treated
157 83 0 Treated
158 84 1 NonTreated
159 84 0 NonTreated
160 85 0 Treated
161 86 1 Treated
162 86 1 Treated
163 86 0 Treated
164 87 1 Treated
165 87 0 Treated
166 88 1 NonTreated
167 88 0 NonTreated
168 89 0 Treated
169 90 0 Treated
170 91 1 NonTreated
171 91 1 NonTreated
172 91 0 NonTreated
173 92 0 NonTreated
174 93 1 NonTreated
175 93 1 NonTreated
176 93 1 NonTreated
177 93 0 NonTreated
178 94 1 Treated
179 94 0 Treated
180 95 0 Treated
181 96 0 Treated
182 97 1 Treated
183 97 1 Treated
184 97 1 Treated
185 97 0 Treated
186 98 1 Treated
187 98 1 Treated
188 98 0 Treated
189 99 0 NonTreated
190 100 1 NonTreated
191 100 0 NonTreated
192 101 0 Treated
193 102 1 Treated
194 102 1 Treated
195 102 0 Treated
196 103 1 NonTreated
197 103 0 NonTreated
198 104 0 NonTreated
199 105 0 NonTreated
200 106 0 Treated
201 107 0 Treated
202 108 1 Treated
203 108 0 Treated
204 109 1 NonTreated
205 109 0 NonTreated
206 110 0 Treated
207 111 0 Treated
208 112 0 Treated
209 113 0 NonTreated
210 114 1 NonTreated
211 114 1 NonTreated
212 114 1 NonTreated
213 114 1 NonTreated
214 114 1 NonTreated
215 114 1 NonTreated
216 114 1 NonTreated
217 114 1 NonTreated
218 114 1 NonTreated
219 114 0 NonTreated
220 115 1 NonTreated
221 115 1 NonTreated
222 115 0 NonTreated
223 116 0 NonTreated
224 117 1 NonTreated
225 117 0 NonTreated
226 118 1 Treated
227 118 0 Treated
228 119 1 NonTreated
229 119 0 NonTreated
230 120 0 NonTreated
231 121 0 NonTreated
232 122 1 NonTreated
233 122 1 NonTreated
234 122 1 NonTreated
235 122 1 NonTreated
236 122 0 NonTreated
237 123 0 Treated
238 124 0 NonTreated
239 125 1 Treated
240 125 0 Treated
241 126 1 Treated
242 126 0 Treated
243 127 0 NonTreated
244 128 1 NonTreated
245 128 0 NonTreated
246 129 1 NonTreated
247 129 1 NonTreated
248 129 0 NonTreated
249 130 0 Treated
250 131 1 NonTreated
251 131 1 NonTreated
252 131 1 NonTreated
253 131 1 NonTreated
254 131 0 NonTreated
255 132 1 NonTreated
256 132 0 NonTreated
257 133 1 NonTreated
258 133 1 NonTreated
259 133 1 NonTreated
260 133 0 NonTreated
261 134 1 NonTreated
262 134 0 NonTreated
263 135 1 NonTreated
264 135 1 NonTreated
265 135 1 NonTreated
266 135 1 NonTreated
267 135 0 NonTreated
268 136 1 NonTreated
269 136 1 NonTreated
270 136 1 NonTreated
271 136 1 NonTreated
272 136 0 NonTreated
273 137 0 NonTreated
274 138 1 Treated
275 138 1 Treated
276 138 1 Treated
277 138 0 Treated
278 139 0 NonTreated
279 140 0 Treated
280 141 1 Treated
281 141 1 Treated
282 141 1 Treated
283 141 0 Treated
284 142 1 Treated
285 142 0 Treated
286 143 1 NonTreated
287 143 0 NonTreated
288 144 1 Treated
289 144 0 Treated
290 145 0 Treated
291 146 1 NonTreated
292 146 0 NonTreated
293 147 1 Treated
294 147 1 Treated
295 147 1 Treated
296 147 1 Treated
297 147 0 Treated
298 148 1 Treated
299 148 0 Treated
300 149 1 Treated
301 149 1 Treated
302 149 0 Treated
303 150 1 Treated
304 150 0 Treated
305 151 0 Treated
306 152 0 Treated
307 153 1 NonTreated
308 153 1 NonTreated
309 153 0 NonTreated
310 154 1 Treated
311 154 1 Treated
312 154 0 Treated
313 155 0 Treated
314 156 1 Treated
315 156 1 Treated
316 156 0 Treated
317 157 0 Treated
318 158 0 Treated
319 159 0 Treated
320 160 1 Treated
321 160 1 Treated
322 160 0 Treated
323 161 0 NonTreated
324 162 0 Treated
325 163 0 NonTreated
326 164 0 Treated
327 165 0 Treated
328 166 0 NonTreated
329 167 0 Treated
330 168 1 NonTreated
331 168 0 NonTreated
332 169 0 NonTreated
333 170 1 NonTreated
334 170 1 NonTreated
335 170 0 NonTreated
336 171 1 NonTreated
337 171 1 NonTreated
338 171 0 NonTreated
339 172 0 Treated
340 173 0 Treated
341 174 1 Treated
342 174 1 Treated
343 174 1 Treated
344 174 1 Treated
345 174 0 Treated
346 175 0 Treated
347 176 1 Treated
348 176 0 Treated
349 177 1 NonTreated
350 177 1 NonTreated
351 177 0 NonTreated
352 178 0 NonTreated
353 179 0 Treated
354 180 1 Treated
355 180 0 Treated
356 181 0 Treated
357 182 0 NonTreated
358 183 1 Treated
359 183 1 Treated
360 183 1 Treated
361 183 1 Treated
362 183 1 Treated
363 183 0 Treated
364 184 1 NonTreated
365 184 0 NonTreated
366 185 1 NonTreated
367 185 0 NonTreated
368 186 1 NonTreated
369 186 1 NonTreated
370 186 1 NonTreated
371 186 0 NonTreated
372 187 1 NonTreated
373 187 1 NonTreated
374 187 0 NonTreated
375 188 0 Treated
376 189 0 Treated
377 190 1 Treated
378 190 1 Treated
379 190 0 Treated
380 191 1 Treated
381 191 1 Treated
382 191 0 Treated
383 192 1 NonTreated
384 192 1 NonTreated
385 192 1 NonTreated
386 192 0 NonTreated
387 193 0 NonTreated
388 194 1 Treated
389 194 0 Treated
390 195 0 Treated
391 196 0 Treated
392 197 0 NonTreated
393 198 1 Treated
394 198 0 Treated
395 199 1 NonTreated
396 199 0 NonTreated
397 200 0 Treated
398 201 1 Treated
399 201 1 Treated
400 201 1 Treated
401 201 1 Treated
402 201 1 Treated
403 201 1 Treated
404 201 0 Treated
405 202 1 NonTreated
406 202 1 NonTreated
407 202 0 NonTreated
408 203 1 Treated
409 203 0 Treated
410 204 0 NonTreated
411 205 0 Treated
412 206 1 Treated
413 206 0 Treated
414 207 0 Treated
415 208 1 Treated
416 208 0 Treated
417 209 1 Treated
418 209 1 Treated
419 209 1 Treated
420 209 1 Treated
421 209 1 Treated
422 209 1 Treated
423 209 0 Treated
424 210 0 Treated
425 211 0 NonTreated
426 212 1 NonTreated
427 212 1 NonTreated
428 212 1 NonTreated
429 212 0 NonTreated
430 213 0 Treated
431 214 1 Treated
432 214 1 Treated
433 214 1 Treated
434 214 1 Treated
435 214 0 Treated
436 215 0 Treated
437 216 0 Treated
438 217 0 Treated
439 218 0 Treated
440 219 1 NonTreated
441 219 1 NonTreated
442 219 1 NonTreated
443 219 0 NonTreated
444 220 1 Treated
445 220 1 Treated
446 220 0 Treated
447 221 1 Treated
448 221 1 Treated
449 221 0 Treated
450 222 0 Treated
451 223 0 Treated
452 224 1 NonTreated
453 224 0 NonTreated
454 225 0 Treated
455 226 1 NonTreated
456 226 0 NonTreated
457 227 0 NonTreated
458 228 1 Treated
459 228 1 Treated
460 228 1 Treated
461 228 1 Treated
462 228 1 Treated
463 228 0 Treated
464 229 1 Treated
465 229 0 Treated
466 230 0 Treated
467 231 0 Treated
468 232 1 NonTreated
469 232 1 NonTreated
470 232 1 NonTreated
471 232 1 NonTreated
472 232 0 NonTreated
473 233 0 NonTreated
474 234 0 Treated
475 235 1 NonTreated
476 235 1 NonTreated
477 235 0 NonTreated
478 236 0 Treated
479 237 1 NonTreated
480 237 0 NonTreated
481 238 0 Treated
482 239 0 Treated
483 240 1 NonTreated
484 240 1 NonTreated
485 240 0 NonTreated
486 241 1 NonTreated
487 241 0 NonTreated
488 242 1 NonTreated
489 242 1 NonTreated
490 242 0 NonTreated
491 243 1 NonTreated
492 243 1 NonTreated
493 243 1 NonTreated
494 243 0 NonTreated
495 244 0 Treated
496 245 0 Treated
497 246 1 Treated
498 246 0 Treated
499 247 1 Treated
500 247 1 Treated
501 247 0 Treated
502 248 0 NonTreated
503 249 0 NonTreated
504 250 1 NonTreated
505 250 0 NonTreated
506 251 1 NonTreated
507 251 0 NonTreated
508 252 1 Treated
509 252 0 Treated
510 253 1 NonTreated
511 253 0 NonTreated
512 254 1 NonTreated
513 254 1 NonTreated
514 254 0 NonTreated
515 255 0 Treated
516 256 1 Treated
517 256 0 Treated
518 257 0 Treated
519 258 0 Treated
520 259 0 NonTreated
521 260 0 Treated
522 261 0 Treated
523 262 1 Treated
524 262 0 Treated
525 263 1 NonTreated
526 263 0 NonTreated
527 264 0 NonTreated
528 265 0 NonTreated
529 266 0 NonTreated
530 267 0 NonTreated
531 268 0 NonTreated
532 269 1 NonTreated
533 269 1 NonTreated
534 269 1 NonTreated
535 269 1 NonTreated
536 269 1 NonTreated
537 269 1 NonTreated
538 269 1 NonTreated
539 269 1 NonTreated
540 269 1 NonTreated
541 269 1 NonTreated
542 269 0 NonTreated
543 270 1 Treated
544 270 1 Treated
545 270 0 Treated
546 271 0 Treated
547 272 1 Treated
548 272 0 Treated
549 273 0 Treated
550 274 1 NonTreated
551 274 1 NonTreated
552 274 1 NonTreated
553 274 1 NonTreated
554 274 1 NonTreated
555 274 1 NonTreated
556 274 1 NonTreated
557 274 1 NonTreated
558 274 1 NonTreated
559 274 1 NonTreated
560 274 1 NonTreated
561 274 1 NonTreated
562 274 1 NonTreated
563 274 1 NonTreated
564 274 1 NonTreated
565 274 1 NonTreated
566 274 0 NonTreated
567 275 1 Treated
568 275 0 Treated
569 276 1 NonTreated
570 276 1 NonTreated
571 276 1 NonTreated
572 276 0 NonTreated
573 277 1 NonTreated
574 277 0 NonTreated
575 278 1 Treated
576 278 1 Treated
577 278 0 Treated
578 279 0 NonTreated
579 280 1 NonTreated
580 280 1 NonTreated
581 280 1 NonTreated
582 280 1 NonTreated
583 280 0 NonTreated
584 281 0 NonTreated
585 282 1 NonTreated
586 282 1 NonTreated
587 282 0 NonTreated
588 283 1 NonTreated
589 283 0 NonTreated
590 284 0 NonTreated
591 285 0 NonTreated
592 286 0 NonTreated
593 287 0 Treated
594 288 1 Treated
595 288 0 Treated
596 289 0 Treated
597 290 1 NonTreated
598 290 0 NonTreated
599 291 0 Treated
600 292 1 NonTreated
601 292 0 NonTreated
602 293 0 NonTreated
603 294 0 Treated
604 295 0 Treated
605 296 1 Treated
606 296 0 Treated
607 297 0 NonTreated
608 298 1 NonTreated
609 298 1 NonTreated
610 298 1 NonTreated
611 298 1 NonTreated
612 298 1 NonTreated
613 298 0 NonTreated
614 299 0 NonTreated
615 300 1 Treated
616 300 0 Treated
617 301 1 NonTreated
618 301 1 NonTreated
619 301 1 NonTreated
620 301 0 NonTreated
621 302 1 Treated
622 302 1 Treated
623 302 0 Treated
624 303 0 Treated
625 304 1 NonTreated
626 304 1 NonTreated
627 304 1 NonTreated
628 304 1 NonTreated
629 304 0 NonTreated
630 305 1 NonTreated
631 305 0 NonTreated
632 306 0 Treated
633 307 1 Treated
634 307 0 Treated
635 308 0 NonTreated
636 309 1 NonTreated
637 309 1 NonTreated
638 309 1 NonTreated
639 309 0 NonTreated
640 310 1 NonTreated
641 310 0 NonTreated
642 311 0 Treated
643 312 0 NonTreated
644 313 0 NonTreated
645 314 0 Treated
646 315 1 Treated
647 315 0 Treated
648 316 1 Treated
649 316 0 Treated
650 317 1 NonTreated
651 317 1 NonTreated
652 317 1 NonTreated
653 317 1 NonTreated
654 317 1 NonTreated
655 317 1 NonTreated
656 317 1 NonTreated
657 317 1 NonTreated
658 317 0 NonTreated
659 318 1 Treated
660 318 1 Treated
661 318 1 Treated
662 318 1 Treated
663 318 1 Treated
664 318 1 Treated
665 318 0 Treated
666 319 0 Treated
667 320 1 NonTreated
668 320 0 NonTreated
669 321 1 Treated
670 321 1 Treated
671 321 0 Treated
672 322 1 Treated
673 322 0 Treated
674 323 0 NonTreated
675 324 1 Treated
676 324 0 Treated
677 325 1 NonTreated
678 325 1 NonTreated
679 325 1 NonTreated
680 325 0 NonTreated
681 326 0 Treated
682 327 1 NonTreated
683 327 1 NonTreated
684 327 1 NonTreated
685 327 1 NonTreated
686 327 0 NonTreated
687 328 0 NonTreated
688 329 0 Treated
689 330 0 NonTreated
690 331 1 Treated
691 331 0 Treated
692 332 0 Treated
693 333 0 Treated
694 334 1 NonTreated
695 334 0 NonTreated
696 335 1 NonTreated
697 335 0 NonTreated
698 336 1 NonTreated
699 336 1 NonTreated
700 336 1 NonTreated
701 336 1 NonTreated
702 336 1 NonTreated
703 336 0 NonTreated
704 337 0 NonTreated
705 338 0 Treated
706 339 1 NonTreated
707 339 1 NonTreated
708 339 0 NonTreated
709 340 0 NonTreated
710 341 0 Treated
711 342 0 NonTreated
712 343 0 NonTreated
713 344 0 Treated
714 345 0 Treated
715 346 0 Treated
716 347 1 NonTreated
717 347 1 NonTreated
718 347 1 NonTreated
719 347 0 NonTreated
720 348 1 NonTreated
721 348 1 NonTreated
722 348 1 NonTreated
723 348 1 NonTreated
724 348 0 NonTreated
725 349 1 NonTreated
726 349 0 NonTreated
727 350 1 NonTreated
728 350 1 NonTreated
729 350 1 NonTreated
730 350 1 NonTreated
731 350 1 NonTreated
732 350 1 NonTreated
733 350 1 NonTreated
734 350 1 NonTreated
735 350 1 NonTreated
736 350 1 NonTreated
737 350 1 NonTreated
738 350 1 NonTreated
739 350 1 NonTreated
740 350 1 NonTreated
741 350 1 NonTreated
742 350 1 NonTreated
743 350 1 NonTreated
744 350 1 NonTreated
745 350 1 NonTreated
746 350 1 NonTreated
747 350 1 NonTreated
748 350 1 NonTreated
749 350 0 NonTreated
750 351 1 NonTreated
751 351 1 NonTreated
752 351 1 NonTreated
753 351 0 NonTreated
754 352 0 NonTreated
755 353 1 NonTreated
756 353 0 NonTreated
757 354 1 NonTreated
758 354 0 NonTreated
759 355 1 Treated
760 355 0 Treated
761 356 0 NonTreated
762 357 1 NonTreated
763 357 0 NonTreated
764 358 0 NonTreated
765 359 0 Treated
766 360 0 Treated
767 361 1 NonTreated
768 361 0 NonTreated
769 362 0 Treated
770 363 0 Treated
771 364 0 Treated
772 365 0 NonTreated
773 366 1 Treated
774 366 0 Treated
775 367 0 Treated
776 368 1 NonTreated
777 368 1 NonTreated
778 368 0 NonTreated
779 369 1 NonTreated
780 369 0 NonTreated
781 370 1 NonTreated
782 370 1 NonTreated
783 370 0 NonTreated
784 371 0 Treated
785 372 0 NonTreated
786 373 0 Treated
787 374 0 Treated
788 375 0 Treated
789 376 0 NonTreated
790 377 0 Treated
791 378 1 NonTreated
792 378 1 NonTreated
793 378 0 NonTreated
794 379 1 Treated
795 379 1 Treated
796 379 1 Treated
797 379 1 Treated
798 379 1 Treated
799 379 0 Treated
800 380 0 NonTreated
801 381 0 Treated
802 382 0 NonTreated
803 383 1 Treated
804 383 0 Treated
805 384 0 Treated
806 385 0 Treated
807 386 0 Treated
808 387 0 NonTreated
809 388 0 NonTreated
810 389 1 Treated
811 389 1 Treated
812 389 1 Treated
813 389 0 Treated
814 390 0 NonTreated
815 391 0 Treated
816 392 1 NonTreated
817 392 0 NonTreated
818 393 1 NonTreated
819 393 1 NonTreated
820 393 1 NonTreated
821 393 1 NonTreated
822 393 1 NonTreated
823 393 0 NonTreated
824 394 1 Treated
825 394 0 Treated
826 395 1 Treated
827 395 0 Treated
828 396 1 Treated
829 396 1 Treated
830 396 1 Treated
831 396 1 Treated
832 396 1 Treated
833 396 0 Treated
834 397 1 NonTreated
835 397 1 NonTreated
836 397 1 NonTreated
837 397 0 NonTreated
838 398 1 Treated
839 398 0 Treated
840 399 1 NonTreated
841 399 1 NonTreated
842 399 1 NonTreated
843 399 1 NonTreated
844 399 1 NonTreated
845 399 1 NonTreated
846 399 1 NonTreated
847 399 1 NonTreated
848 399 1 NonTreated
849 399 1 NonTreated
850 399 1 NonTreated
851 399 0 NonTreated
852 400 0 Treated
853 401 1 NonTreated
854 401 1 NonTreated
855 401 1 NonTreated
856 401 1 NonTreated
857 401 1 NonTreated
858 401 0 NonTreated
859 402 1 NonTreated
860 402 0 NonTreated
861 403 0 Treated

Your problem is not in the code you posten, but right before it. You did not succesfully create readm. To show that, run the following code:
proc print data=readm (obs=9);
run;
(The obs= is just there to limit the listing to 9 observations.)
Somehow, SAS must be informed your fourth column is a text column
You probably wrote someting like
data readm;
infile 'C:\<some path>\<some file>';
input Oss id event chemo;
run;
I would read this as
data readm;
infile 'C:\<some path>\<some file>' truncover dsd dlm='09'x;
input Oss id event chemo $9.;
run;
In this
dcd specifies you have a delimiters
dlm='09'x specifies your delimiters are tabs
`$9.' specifies the chemo field is a character field of up to 9 characters.
truncover specifies you do not want to read the next line to find the last characters of the 'chemo' field on the next line
If this is not realy the answer to your question, tell us how you did creat/import readm and we will see what we can do.
Disclaimer: This code is not tested. If it bugs, please inform me, and I will debug it.

Related

How to convert a string of pixels into an image with python? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am having a string of pixels of a B/W image in this manner:-
48 34 21 18 16 21 26 36 40...44 53 57 64 82 95 9
of string length 547, and I want these pixels to be converted into an image of 48*48 pixel B/W image.
Is there any python library or PyTorch function to make it possible?
Link to the Notebook
You can use PIL.Image.frombuffer() function for example.
from PIL import Image
pixels = '126 126 129 120 110 168 174 172 173 174 170 157 134 97 78 75 118 119 97 117 142 86 58 71 124 161 162 134 100 119 124 118 153 135 143 180 180 172 153 128 98 67 60 75 85 89 85 98 123 126 131 119 119 172 180 171 155 127 100 82 77 72 54 97 184 151 157 176 125 74 71 114 173 171 136 109 116 118 118 150 152 150 178 191 188 187 180 169 152 127 86 60 74 91 92 95 119 131 127 115 113 153 130 94 71 62 65 69 83 95 79 137 181 174 196 148 88 75 103 149 135 107 100 105 104 112 140 162 178 191 187 181 171 166 159 156 159 155 144 97 54 69 83 91 112 116 100 85 74 73 59 58 67 75 74 80 104 110 96 153 180 182 151 100 103 139 167 172 152 141 135 135 141 163 182 191 191 183 179 169 144 127 132 147 156 154 152 143 92 52 56 78 97 86 69 60 51 48 55 65 74 74 71 92 121 122 115 155 177 166 151 158 181 200 201 208 207 198 187 181 182 189 187 187 179 170 154 119 91 86 101 124 139 154 153 153 132 73 51 60 63 52 48 45 46 54 65 78 79 86 96 131 163 146 133 162 179 193 202 211 205 208 216 218 209 204 191 183 184 183 176 170 153 127 96 98 127 148 148 142 134 140 150 154 149 102 49 53 57 58 65 68 70 75 75 74 90 121 151 176 176 148 156 170 193 209 215 211 203 213 219 212 206 201 183 174 173 166 162 135 101 86 99 147 176 175 166 164 157 146 148 155 154 128 55 53 54 54 77 92 89 68 58 61 69 94 143 171 155 150 161 163 185 197 203 202 207 213 212 209 202 195 176 163 157 153 125 83 86 118 160 179 172 165 161 161 166 164 155 155 153 138 74 54 40 70 110 122 106 92 112 123 116 108 96 94 118 146 155 159 166 174 180 187 198 213 216 205 196 192 178 155 139 117 88 96 131 163 159 142 130 126 123 123 132 139 147 156 158 145 75 59 60 117 163 157 138 157 176 179 186 189 167 121 98 105 123 149 161 162 165 178 196 213 214 199 188 181 171 147 117 97 104 124 134 127 123 131 135 139 138 137 144 146 139 147 135 106 75 69 98 155 184 180 178 189 187 182 181 190 203 198 165 126 102 109 138 162 171 193 216 225 222 204 191 182 154 130 116 118 137 143 125 108 100 96 96 102 122 129 145 158 142 96 90 127 88 50 125 175 195 191 191 189 178 166 165 172 175 178 177 162 139 116 112 130 158 194 211 216 218 202 189 165 132 129 134 143 129 104 86 98 80 90 128 97 70 90 117 149 161 109 127 151 112 58 145 187 200 198 192 185 174 171 180 162 135 117 120 126 128 128 124 116 124 157 171 166 156 126 107 92 101 127 129 104 93 105 119 137 113 136 145 136 118 107 119 149 162 147 152 152 125 77 142 183 189 176 177 178 174 163 118 109 118 109 95 83 94 101 114 134 125 120 152 153 154 152 156 124 99 103 122 111 112 136 151 156 163 160 160 163 155 143 145 159 163 137 141 147 126 86 119 158 161 184 183 185 163 100 98 167 135 126 89 99 116 104 101 146 144 115 162 197 201 191 189 156 112 94 103 108 112 127 141 150 153 155 156 148 141 149 156 157 165 155 144 146 129 86 112 140 156 191 190 179 144 126 159 179 160 150 148 143 135 127 135 138 137 117 151 199 195 178 177 169 123 105 100 106 115 132 138 143 145 145 143 139 149 156 156 151 141 141 143 143 130 94 131 136 142 181 198 188 177 189 193 185 183 166 152 136 123 121 130 125 132 143 186 207 192 177 177 169 140 119 128 141 142 147 154 159 158 155 158 156 153 146 132 114 122 136 136 134 127 105 136 143 151 167 184 190 198 189 175 168 160 148 138 131 131 144 160 181 176 168 212 206 202 198 185 173 160 150 133 139 148 155 158 164 165 158 146 133 119 113 118 127 130 127 126 125 124 113 176 181 163 183 177 177 184 186 183 172 164 160 160 164 165 174 189 184 171 206 218 212 206 198 187 180 177 171 157 125 113 116 121 127 126 126 126 129 133 136 134 128 121 118 117 115 113 111 175 199 166 177 196 190 188 189 190 190 188 186 184 182 183 189 179 150 171 208 219 209 201 191 181 173 167 152 150 159 157 148 149 154 155 157 153 146 142 140 130 124 117 112 113 108 100 104 175 199 190 163 181 191 187 187 191 191 189 185 179 170 161 155 150 168 168 185 221 204 193 181 168 165 157 137 120 126 158 167 164 168 168 166 160 152 147 144 138 127 118 113 106 103 95 95 173 196 200 206 189 175 168 169 171 167 166 159 154 155 162 176 190 172 147 191 213 202 193 179 162 158 154 137 124 108 123 155 163 167 169 167 164 157 151 144 135 128 120 113 106 99 92 89 164 192 203 215 214 208 206 193 183 175 173 176 179 185 194 196 182 142 148 202 213 204 202 187 173 165 154 151 135 112 102 131 154 157 162 161 158 149 142 137 129 123 117 108 101 95 88 85 156 189 205 211 206 206 206 202 197 198 194 197 201 201 195 178 156 129 171 211 216 214 208 190 179 171 168 149 132 117 102 112 134 152 154 150 150 143 137 131 123 119 112 103 96 91 83 84 148 189 202 204 201 198 199 201 202 201 197 194 192 191 177 159 133 136 189 206 208 210 199 186 180 176 161 129 129 117 106 114 126 144 149 149 145 141 135 130 122 116 108 98 93 90 81 83 149 190 200 199 194 196 199 194 193 192 185 182 180 172 161 141 129 159 188 186 193 194 185 176 173 164 123 93 105 104 117 127 125 132 145 149 142 137 134 129 119 111 103 96 92 87 79 83 159 190 197 198 190 188 188 186 182 180 174 169 165 160 145 126 134 180 187 154 158 186 175 154 151 137 99 84 87 101 124 130 131 131 140 146 143 136 133 126 117 109 99 92 88 85 76 80 171 189 192 187 184 182 182 179 173 169 168 160 156 148 135 124 158 191 196 172 158 169 146 126 123 117 103 102 104 114 128 132 135 133 133 143 144 138 130 122 112 104 96 90 87 84 76 73 175 190 184 180 178 173 171 169 167 162 159 156 152 139 123 131 177 189 192 188 177 167 147 122 111 101 100 110 116 117 131 133 133 135 134 140 144 138 129 117 108 103 97 95 92 85 76 69 179 191 186 178 171 168 164 162 156 151 153 150 144 131 118 151 181 191 198 193 183 175 163 136 112 109 115 118 121 126 136 132 130 132 129 137 144 140 127 116 108 105 101 99 92 86 76 67 160 190 184 173 169 161 156 152 148 144 146 147 141 120 126 172 184 195 203 200 191 184 174 159 142 139 133 129 133 138 135 131 124 124 127 130 141 145 132 119 112 109 106 104 96 88 73 64 110 184 188 176 168 158 145 143 144 147 146 146 136 115 145 176 184 198 199 196 197 190 178 163 159 157 149 145 144 141 134 129 121 119 126 128 138 151 141 124 117 113 110 106 98 88 69 60 89 172 189 178 170 163 149 138 144 152 155 154 128 128 166 178 184 193 197 200 198 192 182 170 163 168 162 156 147 140 136 132 121 115 118 124 130 155 152 132 126 118 110 106 98 86 66 56 60 157 186 180 173 167 153 142 155 167 166 156 125 151 174 178 178 185 193 189 191 188 175 168 167 162 144 130 126 122 122 124 118 112 117 121 124 155 163 137 129 118 110 107 104 86 63 57 41 140 184 178 178 170 159 154 172 183 181 158 134 161 170 176 176 184 184 169 156 138 129 134 136 114 101 99 100 99 99 98 103 108 119 128 131 160 171 140 126 113 106 112 108 82 64 60 39 116 184 173 179 171 165 161 182 199 198 170 149 170 170 174 185 173 148 132 123 122 126 120 106 109 124 129 124 97 64 61 58 78 112 130 136 165 177 143 121 106 104 124 107 75 63 60 40 86 181 175 176 175 169 162 175 203 203 179 164 179 175 172 143 109 97 84 106 158 175 184 171 164 168 134 76 43 33 65 86 90 105 122 142 174 175 134 116 98 119 135 99 70 60 59 48 69 169 183 173 174 170 164 169 197 209 190 164 179 170 142 130 126 79 44 55 82 127 142 124 112 105 72 54 71 89 111 102 88 96 120 149 180 163 127 110 100 136 126 84 60 57 60 50 59 146 190 174 173 174 168 167 189 204 199 175 164 150 145 168 171 143 111 125 135 144 135 133 139 136 129 128 128 126 112 85 78 102 128 155 174 141 127 100 119 144 114 73 58 60 62 50 50 118 189 181 173 175 171 167 180 196 194 181 166 162 161 163 151 155 164 168 166 164 155 155 155 148 141 135 124 105 85 78 90 122 138 156 149 140 124 98 140 138 94 64 60 63 64 47 48 80 170 191 177 174 180 172 169 187 189 177 170 172 172 169 159 148 142 141 140 139 137 139 133 125 116 106 96 86 81 88 113 122 127 135 142 155 102 119 154 118 76 62 68 65 65 39 46 52 130 185 185 174 182 178 170 174 186 178 171 176 187 178 164 151 135 121 115 118 121 116 110 104 99 93 92 92 93 111 127 125 137 138 161 126 94 144 139 96 70 69 71 61 74 35 40 44 84 166 188 183 176 180 178 174 179 185 180 193 193 180 171 160 150 151 154 152 151 146 141 135 119 108 101 96 102 128 137 145 144 133 126 91 118 147 117 82 74 78 72 61 101 38 36 44 53 127 181 187 178 174 181 180 173 183 190 190 196 195 178 164 161 167 172 168 165 171 163 154 141 128 115 104 117 149 155 139 124 111 96 99 139 135 102 88 86 82 72 64 140 43 37 41 43 75 161 181 183 173 174 179 180 175 190 199 197 198 189 181 173 166 171 173 180 176 158 148 141 126 115 113 129 147 136 132 115 97 91 125 148 124 105 94 87 77 66 82 181 44 41 35 41 45 114 177 177 181 177 175 183 184 176 192 198 184 186 195 198 188 173 174 172 167 157 145 138 121 121 115 113 125 146 133 98 83 111 148 145 122 107 90 85 75 58 118 203 48 44 35 36 42 58 144 181 189 188 182 182 187 181 172 180 189 192 193 198 192 186 178 165 160 152 138 128 128 129 110 111 139 132 105 83 97 143 153 137 118 97 87 79 68 68 168 211 45 45 41 32 38 40 90 163 179 190 184 186 185 189 182 176 185 194 199 187 175 173 162 156 156 145 128 125 127 121 104 111 121 110 89 87 131 153 148 130 106 85 77 71 60 107 199 208'
b = bytes(int(p) for p in pixels.split())
i = Image.frombuffer('L', (48, 48), b)
print(i)
i.save('example.png')
Outputs example.png:
Yun can also use numpy to read the fixed-length data and save to image with cv2.
import numpy as np
import cv2
pixels = '126 126 129 120 110 168 174 172 173 174 170 157 134 97 78 75 118 119 97 117 142 86 58 71 124 161 162 134 100 119 124 118 153 135 143 180 180 172 153 128 98 67 60 75 85 89 85 98 123 126 131 119 119 172 180 171 155 127 100 82 77 72 54 97 184 151 157 176 125 74 71 114 173 171 136 109 116 118 118 150 152 150 178 191 188 187 180 169 152 127 86 60 74 91 92 95 119 131 127 115 113 153 130 94 71 62 65 69 83 95 79 137 181 174 196 148 88 75 103 149 135 107 100 105 104 112 140 162 178 191 187 181 171 166 159 156 159 155 144 97 54 69 83 91 112 116 100 85 74 73 59 58 67 75 74 80 104 110 96 153 180 182 151 100 103 139 167 172 152 141 135 135 141 163 182 191 191 183 179 169 144 127 132 147 156 154 152 143 92 52 56 78 97 86 69 60 51 48 55 65 74 74 71 92 121 122 115 155 177 166 151 158 181 200 201 208 207 198 187 181 182 189 187 187 179 170 154 119 91 86 101 124 139 154 153 153 132 73 51 60 63 52 48 45 46 54 65 78 79 86 96 131 163 146 133 162 179 193 202 211 205 208 216 218 209 204 191 183 184 183 176 170 153 127 96 98 127 148 148 142 134 140 150 154 149 102 49 53 57 58 65 68 70 75 75 74 90 121 151 176 176 148 156 170 193 209 215 211 203 213 219 212 206 201 183 174 173 166 162 135 101 86 99 147 176 175 166 164 157 146 148 155 154 128 55 53 54 54 77 92 89 68 58 61 69 94 143 171 155 150 161 163 185 197 203 202 207 213 212 209 202 195 176 163 157 153 125 83 86 118 160 179 172 165 161 161 166 164 155 155 153 138 74 54 40 70 110 122 106 92 112 123 116 108 96 94 118 146 155 159 166 174 180 187 198 213 216 205 196 192 178 155 139 117 88 96 131 163 159 142 130 126 123 123 132 139 147 156 158 145 75 59 60 117 163 157 138 157 176 179 186 189 167 121 98 105 123 149 161 162 165 178 196 213 214 199 188 181 171 147 117 97 104 124 134 127 123 131 135 139 138 137 144 146 139 147 135 106 75 69 98 155 184 180 178 189 187 182 181 190 203 198 165 126 102 109 138 162 171 193 216 225 222 204 191 182 154 130 116 118 137 143 125 108 100 96 96 102 122 129 145 158 142 96 90 127 88 50 125 175 195 191 191 189 178 166 165 172 175 178 177 162 139 116 112 130 158 194 211 216 218 202 189 165 132 129 134 143 129 104 86 98 80 90 128 97 70 90 117 149 161 109 127 151 112 58 145 187 200 198 192 185 174 171 180 162 135 117 120 126 128 128 124 116 124 157 171 166 156 126 107 92 101 127 129 104 93 105 119 137 113 136 145 136 118 107 119 149 162 147 152 152 125 77 142 183 189 176 177 178 174 163 118 109 118 109 95 83 94 101 114 134 125 120 152 153 154 152 156 124 99 103 122 111 112 136 151 156 163 160 160 163 155 143 145 159 163 137 141 147 126 86 119 158 161 184 183 185 163 100 98 167 135 126 89 99 116 104 101 146 144 115 162 197 201 191 189 156 112 94 103 108 112 127 141 150 153 155 156 148 141 149 156 157 165 155 144 146 129 86 112 140 156 191 190 179 144 126 159 179 160 150 148 143 135 127 135 138 137 117 151 199 195 178 177 169 123 105 100 106 115 132 138 143 145 145 143 139 149 156 156 151 141 141 143 143 130 94 131 136 142 181 198 188 177 189 193 185 183 166 152 136 123 121 130 125 132 143 186 207 192 177 177 169 140 119 128 141 142 147 154 159 158 155 158 156 153 146 132 114 122 136 136 134 127 105 136 143 151 167 184 190 198 189 175 168 160 148 138 131 131 144 160 181 176 168 212 206 202 198 185 173 160 150 133 139 148 155 158 164 165 158 146 133 119 113 118 127 130 127 126 125 124 113 176 181 163 183 177 177 184 186 183 172 164 160 160 164 165 174 189 184 171 206 218 212 206 198 187 180 177 171 157 125 113 116 121 127 126 126 126 129 133 136 134 128 121 118 117 115 113 111 175 199 166 177 196 190 188 189 190 190 188 186 184 182 183 189 179 150 171 208 219 209 201 191 181 173 167 152 150 159 157 148 149 154 155 157 153 146 142 140 130 124 117 112 113 108 100 104 175 199 190 163 181 191 187 187 191 191 189 185 179 170 161 155 150 168 168 185 221 204 193 181 168 165 157 137 120 126 158 167 164 168 168 166 160 152 147 144 138 127 118 113 106 103 95 95 173 196 200 206 189 175 168 169 171 167 166 159 154 155 162 176 190 172 147 191 213 202 193 179 162 158 154 137 124 108 123 155 163 167 169 167 164 157 151 144 135 128 120 113 106 99 92 89 164 192 203 215 214 208 206 193 183 175 173 176 179 185 194 196 182 142 148 202 213 204 202 187 173 165 154 151 135 112 102 131 154 157 162 161 158 149 142 137 129 123 117 108 101 95 88 85 156 189 205 211 206 206 206 202 197 198 194 197 201 201 195 178 156 129 171 211 216 214 208 190 179 171 168 149 132 117 102 112 134 152 154 150 150 143 137 131 123 119 112 103 96 91 83 84 148 189 202 204 201 198 199 201 202 201 197 194 192 191 177 159 133 136 189 206 208 210 199 186 180 176 161 129 129 117 106 114 126 144 149 149 145 141 135 130 122 116 108 98 93 90 81 83 149 190 200 199 194 196 199 194 193 192 185 182 180 172 161 141 129 159 188 186 193 194 185 176 173 164 123 93 105 104 117 127 125 132 145 149 142 137 134 129 119 111 103 96 92 87 79 83 159 190 197 198 190 188 188 186 182 180 174 169 165 160 145 126 134 180 187 154 158 186 175 154 151 137 99 84 87 101 124 130 131 131 140 146 143 136 133 126 117 109 99 92 88 85 76 80 171 189 192 187 184 182 182 179 173 169 168 160 156 148 135 124 158 191 196 172 158 169 146 126 123 117 103 102 104 114 128 132 135 133 133 143 144 138 130 122 112 104 96 90 87 84 76 73 175 190 184 180 178 173 171 169 167 162 159 156 152 139 123 131 177 189 192 188 177 167 147 122 111 101 100 110 116 117 131 133 133 135 134 140 144 138 129 117 108 103 97 95 92 85 76 69 179 191 186 178 171 168 164 162 156 151 153 150 144 131 118 151 181 191 198 193 183 175 163 136 112 109 115 118 121 126 136 132 130 132 129 137 144 140 127 116 108 105 101 99 92 86 76 67 160 190 184 173 169 161 156 152 148 144 146 147 141 120 126 172 184 195 203 200 191 184 174 159 142 139 133 129 133 138 135 131 124 124 127 130 141 145 132 119 112 109 106 104 96 88 73 64 110 184 188 176 168 158 145 143 144 147 146 146 136 115 145 176 184 198 199 196 197 190 178 163 159 157 149 145 144 141 134 129 121 119 126 128 138 151 141 124 117 113 110 106 98 88 69 60 89 172 189 178 170 163 149 138 144 152 155 154 128 128 166 178 184 193 197 200 198 192 182 170 163 168 162 156 147 140 136 132 121 115 118 124 130 155 152 132 126 118 110 106 98 86 66 56 60 157 186 180 173 167 153 142 155 167 166 156 125 151 174 178 178 185 193 189 191 188 175 168 167 162 144 130 126 122 122 124 118 112 117 121 124 155 163 137 129 118 110 107 104 86 63 57 41 140 184 178 178 170 159 154 172 183 181 158 134 161 170 176 176 184 184 169 156 138 129 134 136 114 101 99 100 99 99 98 103 108 119 128 131 160 171 140 126 113 106 112 108 82 64 60 39 116 184 173 179 171 165 161 182 199 198 170 149 170 170 174 185 173 148 132 123 122 126 120 106 109 124 129 124 97 64 61 58 78 112 130 136 165 177 143 121 106 104 124 107 75 63 60 40 86 181 175 176 175 169 162 175 203 203 179 164 179 175 172 143 109 97 84 106 158 175 184 171 164 168 134 76 43 33 65 86 90 105 122 142 174 175 134 116 98 119 135 99 70 60 59 48 69 169 183 173 174 170 164 169 197 209 190 164 179 170 142 130 126 79 44 55 82 127 142 124 112 105 72 54 71 89 111 102 88 96 120 149 180 163 127 110 100 136 126 84 60 57 60 50 59 146 190 174 173 174 168 167 189 204 199 175 164 150 145 168 171 143 111 125 135 144 135 133 139 136 129 128 128 126 112 85 78 102 128 155 174 141 127 100 119 144 114 73 58 60 62 50 50 118 189 181 173 175 171 167 180 196 194 181 166 162 161 163 151 155 164 168 166 164 155 155 155 148 141 135 124 105 85 78 90 122 138 156 149 140 124 98 140 138 94 64 60 63 64 47 48 80 170 191 177 174 180 172 169 187 189 177 170 172 172 169 159 148 142 141 140 139 137 139 133 125 116 106 96 86 81 88 113 122 127 135 142 155 102 119 154 118 76 62 68 65 65 39 46 52 130 185 185 174 182 178 170 174 186 178 171 176 187 178 164 151 135 121 115 118 121 116 110 104 99 93 92 92 93 111 127 125 137 138 161 126 94 144 139 96 70 69 71 61 74 35 40 44 84 166 188 183 176 180 178 174 179 185 180 193 193 180 171 160 150 151 154 152 151 146 141 135 119 108 101 96 102 128 137 145 144 133 126 91 118 147 117 82 74 78 72 61 101 38 36 44 53 127 181 187 178 174 181 180 173 183 190 190 196 195 178 164 161 167 172 168 165 171 163 154 141 128 115 104 117 149 155 139 124 111 96 99 139 135 102 88 86 82 72 64 140 43 37 41 43 75 161 181 183 173 174 179 180 175 190 199 197 198 189 181 173 166 171 173 180 176 158 148 141 126 115 113 129 147 136 132 115 97 91 125 148 124 105 94 87 77 66 82 181 44 41 35 41 45 114 177 177 181 177 175 183 184 176 192 198 184 186 195 198 188 173 174 172 167 157 145 138 121 121 115 113 125 146 133 98 83 111 148 145 122 107 90 85 75 58 118 203 48 44 35 36 42 58 144 181 189 188 182 182 187 181 172 180 189 192 193 198 192 186 178 165 160 152 138 128 128 129 110 111 139 132 105 83 97 143 153 137 118 97 87 79 68 68 168 211 45 45 41 32 38 40 90 163 179 190 184 186 185 189 182 176 185 194 199 187 175 173 162 156 156 145 128 125 127 121 104 111 121 110 89 87 131 153 148 130 106 85 77 71 60 107 199 208'
a = list(map(int, pixels.split(' ')))[:48 * 48]
i = np.array(a).reshape((48, 48)).astype('uint8')
cv2.imwrite('a.png', i)
Outputs a.png.
enter image description here

Excel INDEX MATCH column format into row-column format

I have a huge dataset with ID, MEAN, and DATE (in day of the year). I'm sub-setting it below just for example:
OBJECTID MEAN DATE
1 0.960337524 27
2 1.024530873 27
3 1.07565201 27
4 1.32608937 27
5 1.115863256 27
6 0.738648832 27
7 1.209547088 27
8 1.190287749 27
1 1.311272704 43
2 1.421150386 43
3 1.341622942 43
4 1.343600738 43
5 1.322288454 43
6 1.057037145 43
7 1.262514248 43
8 1.148541133 43
1 1.141311572 75
2 1.12654984 75
3 1.125632558 75
4 1.128487158 75
5 1.181200445 75
6 0.820567181 75
7 0.973662794 75
8 0.903646102 75
In this example, the first date is DAY 27 (Jan 27th). I want to reformat this in Excel so DATE is the horizontal header and ID is the first vertical column like this:
OBJECTID 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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
1
2
3
4
5
6
7
8
How do I use INDEX and MATCH to populate the cells in the blank table above with the values in the dataset? Not all dates in the table will have a value so I need it to populate it with zero like this:
OBJECTID 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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.960337524 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.311272704 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.141311572 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2
3
4
5
6
7
8
This is what I came up with so far:
=IFERROR(INDEX($B$2:$B$2617, MATCH(0, COUNTIF($E2:E2,$B$2:$B$2617)+IF($A$2:$A$2617<>$E2, 1, 0), 0)), 0)
But it doesn't account for the dates with no values. It put the MEAN value for Day 27 into the cell for Day 1.
OBJECTID MEAN DATE OBJECTID 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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
1 0.960337524 27 1 0.960337524
2 1.024530873 27 2
3 1.07565201 27 3
4 1.32608937 27 4
5 1.115863256 27 5
6 0.738648832 27 6
7 1.209547088 27 7
8 1.190287749 27 8
1 1.311272704 43
2 1.421150386 43
3 1.341622942 43
4 1.343600738 43
5 1.322288454 43
6 1.057037145 43
7 1.262514248 43
8 1.148541133 43
1 1.141311572 75
2 1.12654984 75
3 1.125632558 75
4 1.128487158 75
5 1.181200445 75
6 0.820567181 75
7 0.973662794 75
8 0.903646102 75
Any advice or push in the right direction would be appreciated!
On condition that there is only one Mean in your data for each combination of ID and Date the formula below will do the job. (Input is the sheet with your data in it.)
=SUMIFS(Input!$B$2:$B$2617,Input!$A$2:$A$2617,$A2,Input!$C$2:$C$2617,B$1)
However, this formula makes the range management too error prone. Luckily most errors in the range setting will result in a formula error but the process can be much simplified by separating range management from data extraction.
I assigned the name Data to the range Input!$A$2:$C$2617. In fact, you would probably construct this range to be dynamic so that it adjusts to the number of data rows you have automatically. But that is an extra benefit of properly managing ranges which is outside the scope of your present question.
Use the range Data in the above formula you arrive at this:-
=SUMIFS(INDEX(Data,,2),INDEX(Data,,1),$A2,INDEX(Data,,3),B$1)
Either this formula or the one first above introduced can be copied to the right and down to cover your entire output table. If they bother you (as they did me) you can suppress the display of zeros in the sheet or in each cell, using the sheet settings or the cell format to do so.
What you can do is create another unique ID using simple "&" (concat) function. Basically add a 4th column which has the formula
=A2&"_"&C2
The above takes the assumption that your first entry is in 2nd row and this formula is for 2nd row as well which you can drag. Once done then you can apply index match on this new ID.
Hope it helps in clearing your query.

Pascals find the sum

According to above rules what is the maximum sum of below input? It means please take this pyramid as an input (as file or constants directly inside the code) for your implementation and solve by using it.
215
193 124
117 237 442
218 935 347 235
320 804 522 417 345
229 601 723 835 133 124
248 202 277 433 207 263 257
359 464 504 528 516 716 871 182
461 441 426 656 863 560 380 171 923
381 348 573 533 447 632 387 176 975 449
223 711 445 645 245 543 931 532 937 541 444
330 131 333 928 377 733 017 778 839 168 197 197
131 171 522 137 217 224 291 413 528 520 227 229 928
223 626 034 683 839 053 627 310 713 999 629 817 410 121
924 622 911 233 325 139 721 218 253 223 107 233 230 124 233
Note that, each node has only two children here (except the most bottom ones). As an example, you can walk from 215 to 124 (because 193 is a prime) then from 124 to either 237 or 442. From 124 you cannot go to 117 because it’s not a direct child of 124.

What is a valid "letter" for named ranges in Excel?

According to the Excel documentation: Learn about syntax rules for names:
Valid characters The first character of a name must be a letter, an
underscore character (_), or a backslash (). Remaining characters in
the name can be letters, numbers, periods, and underscore characters.
But what exactly is a letter?
I thought this means only ASCII letters, like: A-Z and a-z
But obviously I am wrong, because also the following work (on my English Excel 2013):
German umlauts: Ö,ö,Ü,ü, etc.
French accents: é, ê, etc.
So how can I check in VBA which characters in a string are valid and which are not?
I ran this tiny bit of code:
Sub WhatsInAName()
Dim i As Long, CH As String, r As Range, msg As String
Dim K As Long
Set r = Range("A1")
On Error Resume Next
K = 1
For i = 1 To 255
CH = Chr(i)
r.Name = CH
If Err.Number = 0 Then
Cells(K, 1) = i
K = K + 1
Else
Err.Number = 0
End If
Next i
On Error GoTo 0
End Sub
which should record the ascii codes for valid name starters. I got this:
65
66
68
69
70
71
72
73
74
75
76
77
78
79
80
81
83
84
85
86
87
88
89
90
92
95
97
98
100
101
102
103
104
105
106
107
108
109
110
111
112
113
115
116
117
118
119
120
121
122
131
133
134
135
137
138
140
142
145
146
147
148
150
151
153
154
156
158
159
161
164
167
168
170
173
175
176
177
178
179
180
181
182
183
184
185
186
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
I have no idea why 67 is missing.
EDIT#5:
Here is a list of the valid characters after the first character:
32
46
48
49
50
51
52
53
54
55
56
57
63
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
92
95
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
128
131
133
134
135
136
137
138
140
142
145
146
147
148
150
151
152
153
154
156
158
159
161
164
167
168
170
173
175
176
177
178
179
180
181
182
183
184
185
186
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
Thanks to Martin Trummer.
It turns out that the answer to the question is quite complex. The answer from user
Gary's Student is already quite close, but here are more things to consider:
single-character names:
Examples:
"a" is allowed
"c" is not allowed
characters at the start:
Examples:
"cX" is allowed
"?X" is not allowed
characters after the start
Examples:
"_?" is allowed ("?", "?_" are not)
combinations:
"R1048576C1" invalid
"R1048577C1" valid
"\xx" valid
"\x" invalid
unicode
Workbook names vs. Worksheet names:
e.g. "\a" is allowed on the Worksheet, but not on the Workbook
I've made a GitHub project excel-names which includes an Excel Sheet with a list of valid characters (also unicode) and some VBA code that you can use.
Moreover, the project includes functions that consider the full Excel Name (not only single characters): read the documentation for full details
I know this is old and I might be a litle off topic but I have just ran into a problem whit Excel named ranges.
I was trying to use names like CP01 , CP02, ... and, well, excel keeps telling that those were invalid names although no invalid characters were in the name.
Adding an underscore solves the problem. Names like CP01_ or CP_01 works just fine.
So there is resctriction with valid characters and, as has already been refered, there are also restrictions with the combination of the characters.
I haven't been throug the bottom of the question but, besides the previousily refered combinations of characters, it's not also possible to use any combination of characters that can be interperted as cell adress in A1 notation.

results of Awk command different when executed from a tty versus a script

I want to find line number of file by search word. Two variable, Start line and End line. Start Line must has word "COPY" and End line must has word "\."
When I try type command in stdout.
Find line number of "COPY" word.
-bash-4.1$ cat src_bakfile/merge_cdr_20130901.dat |awk '/COPY/ {print NR;}'
41
285
293
301
309
317
Find line number of "\." word.
-bash-4.1$ cat src_bakfile/merge_cdr_20130901.dat |awk '/\\\./ {print NR;}'
278
286
294
302
310
394
Results OK, correct.
But when I write to shell script and run. Results of find "\." is wrong.
-bash-4.1$ . test_cutbakfile.sh
Start Line ->
41 285 293 301 309 317
End Line ->
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 286 294 302 310 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
This is my shell script.
#!/bin/sh
#-- Config --#
main_path="/home/hdmfec/ibank"
src_path="${main_path}/src_bakfile"
for bakfile in `ls ${src_path}`
do
startlines=`cat ${src_path}/${bakfile} |awk '/COPY/ {print NR;}'`
endlines=`cat ${src_path}/${bakfile} |awk '/\\\./ {print NR;}'`
echo "Start Line ->"
echo ${startlines}
echo -e "\n"
echo "End Line ->"
echo ${endlines}
done
Why's stdout and shell script output not same? please advice me.
Because command substitution (using `backquotes`) treats backquotes specially. You will have to quote every \ again. Or use $() command substitution, as suggested elsewhere.
This should work better:
endlines=`cat ${src_path}/${bakfile} |awk '/\\\\\\./ {print NR;}'`
Better just use $(). It's POSIX compatible. And quote your variables properly around "". Also, using cat is not needed.
for bakfile in $(ls "${src_path}")
do
startlines=$(awk '/COPY/ {print NR;}' "${src_path}/${bakfile}")
endlines=$(awk '/\\\./ {print NR;}' "${src_path}/${bakfile}")
You need to use double quotes in your echo statements. Have your script like this:
startlines=$(cat ${src_path}/${bakfile} |awk '/COPY/ {print NR;}')
endlines=$(cat ${src_path}/${bakfile} |awk '/\\\./ {print NR;}')
echo "Start Line ->"
echo "${startlines}"
echo -e "\n"
echo "End Line ->"
echo "${endlines}"
Without double quotes shell prints new lines as space since shell treats all individual strings as a separate argument without quotes.
PS: You should also avoid parsing ls's output and use find instead like this:
while read bakfile; do
startlines=$(cat ${src_path}/${bakfile} |awk '/COPY/ {print NR;}')
endlines=$(cat ${src_path}/${bakfile} |awk '/\\\./ {print NR;}')
echo "Start Line ->"
echo "${startlines}"
echo -e "\n"
echo "End Line ->"
echo "${endlines}"
done < <(find "$src_path" -type f -maxdepth 1)

Resources