How to column input in SAS - sas
My data set is below and I need to type it out in column format.
I don't understand how to read it and figure out which column ranges to put in next to the variables. I see people put 1-2, 4-7, etc. next to the variables but where is that coming from??
input id team $ startweight endweight;
1023 red 189 165
1049 yellow 145 124
1219 red 210 192
1246 yellow 194 177
1078 red 127 118
1221 yellow 220 .
1095 blue 135 127
1157 green 155 141
1331 blue 187 172
1067 green 135 122
1251 blue 181 166
1333 green 141 129
1192 yellow 152 139
1352 green 156 137
1262 blue 196 180
1087 red 148 135
1124 green 156 142
1197 red 138 125
1133 blue 180 167
1036 green 135 123
1057 yellow 146 132
1328 red 155 142
1243 blue 134 122
1177 red 141 130
1259 green 189 172
1017 blue 138 127
1099 yellow 148 132
1329 yellow 188 174
;
run;
SAS has a number of ways to read in data.
With list input, you just ... list ... out the columns!
input id team $ startweight endweight;
However, that relies on the columns being in a delimited format - meaning, there is some character (space, comma, etc.) separating the fields.
If that's not the case, and instead it's just positional, character by character - meaning, the first two characters are always the ID, the next 4 characters are the team, etc. - then you can use column input or formatted input.
Column input:
input id 1-2 team $ 4-7 startweight 8-15 endweight 16-23;
Formatted input:
input #1 id 2. #4 team $4. #8 startweight 8. #16 endweight 8. ;
Column input just puts the start-end column after the variable name, optionally with $ for character variables. Formatted input goes further; it uses pointer control to say where to start, and then it gives an informat to define how to input the data. The informat is useful when you're, say, inputting date values.
See the documentation for the input statement for more information on various input types (including several fun ones not mentioned here!)
This would input your example data:
data want;
input
id 1-4
team $ 6-11
startweight 13-15
endweight 17-19
;
datalines;
1023 red 189 165
1049 yellow 145 124
1219 red 210 192
1246 yellow 194 177
1078 red 127 118
1221 yellow 220 .
1095 blue 135 127
1157 green 155 141
1331 blue 187 172
1067 green 135 122
1251 blue 181 166
1333 green 141 129
1192 yellow 152 139
1352 green 156 137
1262 blue 196 180
1087 red 148 135
1124 green 156 142
1197 red 138 125
1133 blue 180 167
1036 green 135 123
1057 yellow 146 132
1328 red 155 142
1243 blue 134 122
1177 red 141 130
1259 green 189 172
1017 blue 138 127
1099 yellow 148 132
1329 yellow 188 174
;
run;
As would this:
data want;
input
#1 id 4.
#6 team $6.
#13 startweight 3.
#17 endweight 3.
;
datalines;
1023 red 189 165
1049 yellow 145 124
1219 red 210 192
1246 yellow 194 177
1078 red 127 118
1221 yellow 220 .
1095 blue 135 127
1157 green 155 141
1331 blue 187 172
1067 green 135 122
1251 blue 181 166
1333 green 141 129
1192 yellow 152 139
1352 green 156 137
1262 blue 196 180
1087 red 148 135
1124 green 156 142
1197 red 138 125
1133 blue 180 167
1036 green 135 123
1057 yellow 146 132
1328 red 155 142
1243 blue 134 122
1177 red 141 130
1259 green 189 172
1017 blue 138 127
1099 yellow 148 132
1329 yellow 188 174
;
run;
Related
How to shift side-by-side bars in Proc SGPLOT for Time Data? discreteoffset doesn't work with (type=time) option
I am currently trying to create a side-by-side dual axis bar chart in proc sgplot for the data which is based on dates. I am currently stuck at last thing, where I am not able to shift the bars using discreteoffset option on vbar, because I am using Type=time on xaxis. If I comment this, then the bars are shifted but then the xaxis tick values look clumsy. So I wonder if there is any other option that can move the bars for Date/time Data? Following is my SAS code. data input; input people visits outcome date date9.; datalines; 41 448 210 1-Jan-18 43 499 207 1-Feb-18 45 544 221 1-Mar-18 49 564 239 1-Apr-18 39 575 236 1-May-18 37 549 210 1-Jun-18 51 602 263 1-Jul-18 32 586 208 1-Aug-18 52 557 225 1-Sep-18 41 534 227 1-Oct-18 48 499 217 1-Nov-18 44 514 235 1-Dec-18 31 582 281 1-Jan-19 33 545 269 1-Feb-19 38 574 259 1-Mar-19 29 564 247 1-Apr-19 29 642 274 1-May-19 28 556 216 1-Jun-19 20 531 187 1-Jul-19 31 604 226 1-Aug-19 19 513 186 1-Sep-19 24 483 185 1-Oct-19 28 401 156 1-Nov-19 18 450 158 1-Dec-19 21 418 178 1-Jan-20 28 396 149 1-Feb-20 43 488 177 1-Mar-20 33 539 205 1-Apr-20 57 631 244 1-May-20 54 695 291 1-Jun-20 58 732 309 1-Jul-20 62 681 301 1-Aug-20 42 654 291 1-Sep-20 57 749 365 1-Oct-20 60 627 249 1-Nov-20 56 623 244 1-Dec-20 54 712 298 1-Jan-21 62 655 262 1-Feb-21 ; run; proc sgplot data=input; format date monyy7.; styleattrs datacolors=(Red DarkBlue) datacontrastcolors=(black black) datalinepatterns=(solid); vbar date / response=visits discreteoffset=-0.17 barwidth=0.3; vbar date / response=outcome discreteoffset=0.17 barwidth=0.3; vline date / response=people y2axis lineattrs=(color=black thickness=3); xaxis display=(nolabel) /*fitpolicy=rotate valuesrotate=vertical*/ type=time /*interval=month*/; yaxis grid label='Label1' values=(0 to 800 by 100); y2axis label='Label2' values=(0 to 70 by 10); keylegend / title=""; run; Output I am getting: Output I want: (With shifted bars, but it is changing dates) Appreciate any help! Thank you.
Reshape the data with transpose so the variables wanted side by side become categorical, i.e. name value pairs. The name can be used in vbar as the group= with groupdisplay=cluster. Note: The xaxis type=time appears to perform special checks based on the format of the vbar variable, and will rendered a pretty two-line axis label when that format is date9. I've never seen this discussed in the documentation. Example: Uses name= in the plotting statements so the keylegend can look prettier. proc transpose data=input out=plot; by rowid date; copy people; var visits outcome; run; proc sgplot data=plot; vbar date / response=col1 group=_name_ groupdisplay=cluster name='relatedcounts'; vline date / response=people group=_name_ y2axis lineattrs=(color=black thickness=3) name='people'; xaxis type = time interval = month ; format date date9.; yaxis grid label='Related counts' values=(0 to 800 by 100); y2axis label='# People' values=(0 to 70 by 10); keylegend 'relatedcounts' / title=""; run; Will produce
Clojure: Sets, order and purity
Is (vec #{1 2 3}) guaranteed to always return [1 3 2] or could the order be different? I am not so much interested in the implementation details behind this but going from unordered to ordered in general in order to keep my functions pure and easily testable.
As mentioned, standard #{} sets (both PersistentArrayMap and PersistentHashMap; depending on the size) are considered unordered. Regarding purity with respect to calling seq on a set though, the current implementation does seem to return a well-defined, consistent order; just not an easily predictable one: (let [r (range 1000) seqs (repeatedly 1000 #(seq (add-randomly #{} r)))] ; See how many different orders were produced (println (count (set seqs))) (println (first seqs))) 1 (0 893 920 558 453 584 487 637 972 519 357 716 950 275 530 929 789 389 586 410 433 765 521 451 291 443 798 779 970 249 638 299 121 734 287 65 702 70 949 218 648 812 62 74 774 475 497 580 891 164 282 769 799 273 186 430 641 529 898 370 834 233 298 188 240 110 130 982 620 311 931 882 128 399 989 377 468 259 210 229 153 621 213 670 977 343 958 887 472 7 894 59 934 473 86 756 830 613 491 154 20 224 355 592 610 806 571 466 72 454 888 463 851 770 814 859 58 964 980 205 555 552 60 835 459 175 322 510 662 27 352 493 899 416 777 694 1 631 854 69 101 24 901 547 102 788 713 385 988 135 397 773 490 752 354 884 360 998 961 55 568 797 688 763 269 676 448 527 206 966 165 715 387 652 683 85 721 862 615 681 225 865 297 39 805 274 88 217 46 682 508 149 415 239 478 878 157 345 300 743 921 4 550 204 470 646 77 106 197 405 897 726 776 940 755 902 518 232 260 823 267 119 319 534 222 603 293 95 450 329 144 504 819 818 505 723 992 176 863 471 349 512 710 192 54 92 221 141 502 871 464 801 307 935 758 290 627 517 361 264 137 356 728 976 678 327 234 856 817 104 353 15 48 945 759 242 832 969 50 956 917 557 251 394 116 585 583 75 437 516 994 930 967 687 159 848 995 709 99 540 645 749 479 890 630 916 815 281 402 669 781 740 975 429 309 458 21 388 495 952 626 875 31 113 32 811 827 407 398 136 691 847 825 139 506 396 460 483 589 581 932 174 578 855 331 363 284 208 305 955 796 708 182 256 657 514 731 619 985 485 214 193 685 804 869 836 785 635 442 561 954 656 607 241 314 782 226 235 672 420 418 262 263 304 401 673 40 129 600 729 467 445 317 294 91 810 364 987 880 515 412 553 974 341 117 665 523 172 601 108 156 358 308 908 649 531 923 223 419 365 944 181 417 979 278 56 942 33 13 867 22 618 380 257 338 500 909 993 168 833 496 947 347 501 596 872 792 90 237 826 292 109 216 191 498 829 761 375 525 367 143 742 178 640 247 328 391 990 167 707 36 41 474 187 551 996 528 971 599 376 195 889 316 668 428 303 671 794 905 368 560 565 310 366 118 522 150 886 313 384 567 238 846 962 845 196 162 393 184 219 999 461 89 100 426 604 477 844 541 351 243 131 790 963 629 873 122 933 43 231 61 654 883 598 413 29 784 800 151 369 348 575 693 44 739 258 250 674 539 301 838 424 93 6 684 951 573 408 563 850 616 866 111 997 689 28 456 374 608 737 548 538 895 411 957 134 943 64 623 465 816 334 323 189 280 198 155 295 808 248 587 285 507 227 724 476 941 911 853 494 220 842 103 697 611 170 51 25 261 768 822 201 904 590 489 778 166 447 34 252 978 775 325 594 436 828 535 813 146 741 876 228 907 306 125 276 340 148 482 622 588 17 312 606 3 520 760 720 286 279 879 536 663 12 440 332 330 382 152 544 803 642 435 342 703 783 695 973 2 948 66 484 439 236 556 373 142 359 727 371 772 444 570 757 107 532 984 23 745 719 230 625 47 526 180 786 870 537 659 158 991 350 35 849 644 881 127 927 675 383 533 910 302 564 701 566 821 787 82 76 735 492 718 771 215 97 704 277 926 751 19 335 597 938 57 609 202 68 452 200 868 11 115 946 983 339 431 462 337 698 255 503 546 9 953 857 706 632 457 427 145 5 733 624 831 244 918 824 289 112 925 730 699 712 414 839 802 860 179 344 481 732 661 245 378 913 906 658 266 324 793 680 446 524 254 404 617 283 513 572 705 959 83 634 138 346 14 455 265 449 333 650 639 569 326 746 647 45 53 559 78 924 562 542 912 664 315 914 480 132 753 900 26 766 123 203 667 392 577 807 140 321 795 441 700 268 840 16 320 133 288 381 605 163 81 120 643 79 211 38 173 126 981 421 593 636 98 422 423 614 762 582 666 554 409 574 595 124 747 171 87 169 653 679 843 160 30 400 767 896 928 696 738 809 509 736 207 874 434 690 194 511 73 486 336 96 837 937 10 660 272 499 488 903 386 270 576 717 543 271 18 395 403 469 105 185 52 545 633 114 968 253 612 628 748 209 147 655 750 852 425 864 67 296 602 318 161 651 725 372 406 438 780 711 71 939 579 877 722 42 919 80 885 986 714 677 199 841 754 791 861 591 744 960 37 183 965 892 432 379 63 212 94 362 8 686 692 764 246 190 549 922 177 915 936 820 49 858 390 84) So yes, it seems that within a single run of a program, the order of (seq #{1 2 3}) can be relied upon, and can be considered pure. The language gives no guarantees though, and this property may not always exist, so really, I wouldn't rely on it. It's an implementation detail. If you require a consistent ordering, it may be beneficial to have a vector along with the set to define the order. You could do something like: (def pair [#{} []]) (defn add [p n] (-> p (update 0 conj n) (update 1 conj n))) (-> pair (add 1) (add 2)) => [#{1 2} [1 2]] Reference the set when you want to do a membership test, and the vector when you need order. Of course, this requires twice as much memory as it otherwise would though, so this may not always be practical. Additions to both sets and vectors are essentially constant however, so additions will still be quick.
double free or corruption (fasttop): 0x000000000063d070 *** c++ sieve program
I am writing a sieve program in c++. But for every legitimate input, the program always produces output with 4 primes founded and "2 3 5", no matter how the input varies. As I try to run the program via the console, it gives an error message saying that double free or corruption (fasttop): 0x000000000063d070 ***. Btw, I am new to c++. And also, I am trying to format the output correctly, but the they are just flying around. This is the desired format. 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709 719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 911 919 929 937 941 947 953 967 971 977 983 991 997
Aside from your double-free being caused by calling the destructor explicitly as #PaulMcKenzie said in the comments, your problem with only outputting the first few primes is because of this line: int n = sizeof(is_prime_); is_prime_ is a pointer and so its size is fixed at compile time (probably 4 or 8 bytes depending on your system). You already have limit_ as a value, you should use that to work out your n.
Verifying output to "Find the numbers between 1 and 1000 whose prime factors' sum is itself a prime" from Allain's Jumping into C++ (ch7 #3)
The question: Design a program that finds all numbers from 1 to 1000 whose prime factors, when added together, sum up to a prime number (for example, 12 has prime factors of 2, 2, and 3, which sum to 7, which is prime). Implement the code for that algorithm. I modified the problem to only sum unique factors, because I don't see why you'd count a factor twice, as in his example using 12. My solution. Is there any good (read: automated) way to verify the output of my program? Sample output for 1 to 1000: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 17 19 20 22 23 24 25 26 28 29 30 31 34 37 40 41 43 44 46 47 48 49 52 53 58 59 60 61 63 67 68 70 71 73 76 79 80 82 83 88 89 92 94 96 97 99 101 103 107 109 113 116 117 118 120 121 124 127 131 136 137 139 140 142 147 148 149 151 153 157 160 163 164 167 169 171 172 173 176 179 181 184 188 189 191 192 193 197 198 199 202 207 210 211 212 214 223 227 229 232 233 239 240 241 244 251 252 257 261 263 268 269 271 272 273 274 275 277 279 280 281 283 286 289 292 293 294 297 298 306 307 311 313 317 320 325 331 332 333 334 337 347 349 351 352 353 358 359 361 367 368 369 373 376 379 382 383 384 388 389 394 396 397 399 401 404 409 412 414 419 421 423 424 425 428 431 433 439 443 449 454 457 459 461 462 463 464 467 468 472 475 478 479 480 487 491 495 499 503 509 513 521 522 523 524 529 531 538 539 541 544 546 547 548 549 550 557 560 561 562 563 567 569 571 572 575 577 587 588 593 594 599 601 603 604 605 607 612 613 617 619 621 622 628 631 639 640 641 643 646 647 651 652 653 659 661 664 668 673 677 683 684 691 692 694 701 704 709 712 714 718 719 725 726 727 733 736 738 739 741 743 751 752 756 757 759 761 764 765 768 769 772 773 775 777 783 787 792 797 798 801 809 811 821 823 825 827 828 829 833 837 838 839 841 846 847 848 850 853 856 857 859 862 863 873 877 881 883 887 891 892 903 904 907 908 909 911 918 919 922 925 928 929 932 937 941 944 947 953 954 957 960 961 966 967 971 975 977 981 983 991 997 999 Update: I have solved my problem and verified the output of my program using an OEIS given series, as suggested by #MVW (shown in the source given by my new github solution). In the future, I will aim to test my programs by doing zero or more of the following (depending on the scope/importance of the problem): google keywords for an existing solution to the problem, comparing it against my solution if I find it unit test components for correctness as they're built and integrated, comparing these tests with known correct outputs
Some suggestions: You need to check the properties of your calculated numbers. Here that means calculating the prime factors and calculating their sum and testing if that sum is a prime number. Which is what your program should do in the first place, by the way. So one nice option for checking is comparing your output with a known solution or the output of a another program which is known to work. The tricky bit is to have such a solution or program available. And I neglect that your comparison could be plagued by errors as well :-) If you just compare it with other implementations, e.g. programs from other folks here, it would turn out more of a voting, it would not be a proof. It would just give increased probability that your program is correct, if several independent implementations come up with the same result. Of course all implementations could err :-) The more agree the better. And the more diverse the implementations are, the better. E.g. you could use different programming languages, algebraic systems or a friend with time and paper and pencil and Wikipedia. :-) Another means is to add checks to your intermediate steps, to get more confidence in your result. Kind of building a chain of trust. You could output the prime factors you determined and compare it with the output of a prime factorization program which is known to work. Then you check if your summing works. Finally you could check if the primality test you apply to the candidate sums is working correctly by feeding it with known prime numbers and non prime numbers and so on. That is kind of what folks do with unit testing for example. Trying to cover most parts of the code as working, hoping if the parts work, that the whole will work. Or you could formally prove your program step by step, using Hoare Calculus for example or another formal method. But that is tricky, and you might end up shifting program errors to errors in the proof. And today, in the era of internet, of course, you could internet search for the solution: Try searching for sum of prime factors is prime in the online encyclopedia of integer sequences, which should give you series A100118. :-) It is the problem with multiplicity, but shows you what the number theory pros do, with Mathematica and program fragments to calculate the series, the argument for the case of 1 and literature. Quite impressive.
Here's the answer I get. I exclude 1 as it has no prime divisors so their sum is 0, not a prime. Haskell> filter (isPrime . sum . map fst . primePowers) [2..1000] [2,3,4,5,6,7,8,9,10,11,12,13,16,17,18,19,20,22,23,24,25,27,29,31,32,34,36,37,40, 41,43,44,47,48,49,50,53,54,58,59,61,64,67,68,71,72,73,79,80,81,82,83,88,89,96,97 ,100,101,103,107,108,109,113,116,118,121,125,127,128,131,136,137,139,142,144,149 ,151,157,160,162,163,164,165,167,169,173,176,179,181,191,192,193,197,199,200,202 ,210,211,214,216,223,227,229,232,233,236,239,241,242,243,250,251,256,257,263,269 ,271,272,273,274,277,281,283,284,288,289,293,298,307,311,313,317,320,324,328,331 ,337,343,345,347,349,352,353,358,359,361,367,373,379,382,383,384,385,389,390,394 ,397,399,400,401,404,409,419,420,421,428,431,432,433,435,439,443,449,454,457,461 ,462,463,464,467,472,478,479,484,486,487,491,495,499,500,503,509,512,521,523,529 ,538,541,544,547,548,557,561,562,563,568,569,570,571,576,577,578,587,593,595,596 ,599,601,607,613,617,619,622,625,630,631,640,641,643,647,648,651,653,656,659,661 ,665,673,677,683,691,694,701,704,709,714,715,716,719,727,729,733,739,743,751,757 ,759,761,764,768,769,773,777,780,787,788,795,797,798,800,808,809,811,819,821,823 ,825,827,829,838,839,840,841,853,856,857,858,859,862,863,864,877,881,883,885,887 ,903,907,908,911,919,922,924,928,929,930,937,941,944,947,953,956,957,961,967,968 ,971,972,977,983,991,997,1000] Haskell> primePowers 12 [(2,2),(3,1)] Haskell> primePowers 14 [(2,1),(7,1)] You could hard-code this list in and test against it. I'm pretty confident these results are without error. (read . is "of").
How to draw a (bezier) path with a fill color using GDI+?
I am making a SVG renderer for Windows using the Windows API and GDI+. SVG allows setting the 'fill' and 'stroke' style attributes on a Path. I am having some difficulty with the implementation of the 'fill' attribute. The following path represents a spiral: <svg:path style="fill:yellow;stroke:blue;stroke-width:2" d="M153 334 C153 334 151 334 151 334 C151 339 153 344 156 344 C164 344 171 339 171 334 C171 322 164 314 156 314 C142 314 131 322 131 334 C131 350 142 364 156 364 C175 364 191 350 191 334 C191 311 175 294 156 294 C131 294 111 311 111 334 C111 361 131 384 156 384 C186 384 211 361 211 334 C211 300 186 274 156 274" /> The fill color is yellow, and it should fill the entire shape, this is however what I get: My GDI+ calls look like this: Gdiplus::GraphicsPath bezierPath; bezierPath.AddBeziers(&gdiplusPoints[0], gdiplusPoints.size()); g.FillPath(&solidBrush, &bezierPath); g.DrawPath(&pen, &bezierPath); Apparently the code is correct for drawing the shape, but not for filling it. Can anyone help me in figuring out what's going wrong?
Try to set the FillMode property of your GraphicsPath to FillMode::Winding, an alternate filling method that should suits your needs.