Having trouble importing data with sets in SAS - sas

data testData;
INFILE DATALINES;
INPUT crop $ 1-11 [month1] 12-23 [month2] 25-36 [month3] 38-49;
datalines;
Corn 16 27 31 33 15 23 30 30 16 27 27 26
Corn 18 20 25 23 15 15 31 32 15 32 32 15
Corn 12 15 16 73 . . . . . . . .
Soybeans 20 23 23 25 24 24 25 32 21 25 23 24
Soybeans 27 45 24 12 12 13 15 42 22 32 31 43
Cotton 31 32 33 34 29 24 26 28 34 32 28 45
Cotton 26 25 23 24 53 48 75 26 34 35 25 78
Sugarbeets 22 23 25 42 25 25 24 26 34 25 16 52
Sugarbeets 54 23 21 54 25 43 32 15 26 54 2 54
Clover 12 45 32 54 24 58 25 34 87 54 61 21
Clover 51 31 31 16 96 48 54 62 31 31 11 11
Clover 56 13 13 71 32 13 27 32 36 26 54 32
Clover 53 08 06 54 32 32 62 16 . . . .
;
I don't have much guidance on what this data actually is (it's a school question) so I'm assuming that the number sets are harvests per week per month. I'm fairly new to SAS so I might be going in the complete wrong direction, but I thought tossing the months in arrays would be the best bet. I added the periods because there is some missing data.
The issue with this code is that I get this error:
ERROR 22-322: Expecting a name.
ERROR: Undeclared array referenced: NAME.
But it seems like the [month1] should be naming the array, right? I've also tried this:
data testData;
INFILE DATALINES;
array crop{*} $ 1-11;
array month1{*} 12-23;
array month2{*} 25-36;
array month3{*} 38-49;
datalines;
Corn 16 27 31 33 15 23 30 30 16 27 27 26
Corn 18 20 25 23 15 15 31 32 15 32 32 15
Corn 12 15 16 73 . . . . . . . .
Soybeans 20 23 23 25 24 24 25 32 21 25 23 24
Soybeans 27 45 24 12 12 13 15 42 22 32 31 43
Cotton 31 32 33 34 29 24 26 28 34 32 28 45
Cotton 26 25 23 24 53 48 75 26 34 35 25 78
Sugarbeets 22 23 25 42 25 25 24 26 34 25 16 52
Sugarbeets 54 23 21 54 25 43 32 15 26 54 2 54
Clover 12 45 32 54 24 58 25 34 87 54 61 21
Clover 51 31 31 16 96 48 54 62 31 31 11 11
Clover 56 13 13 71 32 13 27 32 36 26 54 32
Clover 53 08 06 54 32 32 62 16 . . . .
;
I'm not sure which method I should be using or if I'm even going in the right direction with this dataset.

For what I can tell you have crop value for 12 separate time points - so twelve months?
In the input statement you just need to define a variable name for all your columns which you are providing in your "datalines" statement. This can just be defined as:
data testData;
INFILE DATALINES;
Input Crop $ month1-month12;
datalines;
Corn 16 27 31 33 15 23 30 30 16 27 27 26
Corn 18 20 25 23 15 15 31 32 15 32 32 15
Corn 12 15 16 73 . . . . . . . .
Soybeans 20 23 23 25 24 24 25 32 21 25 23 24
Soybeans 27 45 24 12 12 13 15 42 22 32 31 43
Cotton 31 32 33 34 29 24 26 28 34 32 28 45
Cotton 26 25 23 24 53 48 75 26 34 35 25 78
Sugarbeets 22 23 25 42 25 25 24 26 34 25 16 52
Sugarbeets 54 23 21 54 25 43 32 15 26 54 2 54
Clover 12 45 32 54 24 58 25 34 87 54 61 21
Clover 51 31 31 16 96 48 54 62 31 31 11 11
Clover 56 13 13 71 32 13 27 32 36 26 54 32
Clover 53 08 06 54 32 32 62 16 . . . .;
run;
Arrays are used to refer to already existing variables, so to my knowledge not to declare variables as you want to do here.

Related

cost of cutting a plank

I know that this question has been asked but i cant understand the problem in my code. I know that we have to use cost in desending order for minimum cost and i did same but still gives wrong output.
A board composed of m×n wooden squares and asks him to find the minimum cost of breaking the board back down into individual 1×1 pieces. To break the board down, Bob must make cuts along its horizontal and vertical lines.
To reduce the board to squares, xn−1 vertical cuts must be made at locations x1,x2,…,xn−2,xn−1 and ym−1 horizontal cuts must be made at locations y1,y2,…,ym−2,ym−1. Each cut along some xi (or yj) has a cost, cxi (or cyj). If a cut of cost c passes through n already-cut segments, the total cost of the cut is n×c.
The cost of cutting the whole board down into 1×1 squares is the sum of the cost of each successive cut. Recall that the cost of a cut is multiplied by the number of already-cut segments it crosses through, so each cut is increasingly expensive.
Input Format
The first line contains a single integer, T, denoting the number of test cases. The subsequent 3T lines describe each test case in 3 lines.
For each test case, the first line has two positive space-separated integers, m and n, detailing the respective height (y) and width (x) of the board.
The second line has m−1 space-separated integers listing the cost, cyj, of cutting a segment of the board at each respective location from y1,y2,…,ym−2,ym−1.
The third line has n−1 space-separated integers listing the cost, cxi, of cutting a segment of the board at each respective location from x1,x2,…,xn−2,xn−1.
Note: If we were to superimpose the m×n board on a 2D graph, x0, xn, y0, and yn would all be edges of the board and thus not valid cut lines.
Constraints
1≤T≤20
2≤m,n≤1000000
,0≤cxi,cyj≤1000000000
Output Format
For each of the T test cases, find the minimum cost (MinimumCost) of cutting the board into 1×1 squares and print the value of MinimumCost % (1000000000+7).
#include <iostream>
#include <limits>
using namespace std;
int main() {
int t,ch=0;
long int pos,m,n,h=1,l=1;
long long int cost=0,*x,*y,temp;
cin>>t;
while(t>0)
{cin>>m>>n;
cost=0;
x = new long long int[n-1];
y = new long long int[m-1];
for (long i=0;i<m-1;i++)
cin>>y[i];
for(long i=0;i<n-1;i++)
cin>>x[i];
h=1;
l=1;
while((h!=m)|(l!=n))
{ch=0;
temp=0;
for (long i=0;i<m-1;i++)
if (temp<y[i])
{temp=y[i];
pos=i;
}
for(long i=0;i<n-1;i++)
if (temp<x[i])
{temp=x[i];
pos=i;
ch=1;
}
cost=cost+temp*(ch==0?l:h);
if (ch==0)
{y[pos]=-1;
h++;}
else
{x[pos]=-1;
l++;
}
}
cout<<cost%1000000007;
t--;
}
return 0;
}
Test case that gives wrong output:
Input:
5
52 30
2 30 79 47 4 56 47 67 25 30 75 58 47 54 66 61 6 64 28 41 75 36 1 92 42 61 35 56 12 86 84 14 68 63 13 72 19 60 39 96 43 14 55 42 21 73 3 27 37 84 68
64 72 21 56 14 35 44 71 47 82 7 14 50 71 79 23 42 92 14 39 35 81 46 29 2 19 84 81 57
23 43
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23
60 76
7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
58 40
71 58 61 51 33 3 43 48 94 30 29 40 59 83 12 43 64 69 64 65 42 57 40 72 64 98 98 47 56 6 85 79 65 46 30 98 49 25 98 96 7 27 88 66 10 0 62 26 69 78 92 64 87 84 88 51 35
87 50 91 45 35 22 62 81 53 61 83 30 59 31 38 39 19 56 1 20 70 28 41 48 72 57 35 56 46 39 91 85 41 34 30 77 57 93 10
47 94
6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17
Output
51028
1912
33638
91124
27525
This line could be a contributing factor:
while((h!=m)|(l!=n))
The | operator is a binary arithmetic operator.
Maybe you were looking for ||, which is the logical OR operator:
while((h!=m) || (l!=n))

Getting WA in ANUGCD from Codechef March Long Contest

I am Getting WA in the Question GCD Condition from Codechef March Long Contest.
Kindly tell me what I've done wrong or some test case where the code produces Wrong answer.
Link for the Question
I Have used RMQ(Range maximum Query) for every prime number
for(i=0;i<limit;i++)
{
int sz=b[i].size();
if(!sz)continue;
int level=0;
cc[i].resize(sz);
for(j=0;j<sz;j++)cc[i][j].push_back(b[i][j]);//level 0
for(level=1;(1<<level)<=sz;level++)
{
for(j=0;j+(1<<level)<=sz;j++)
{
int c1=cc[i][j][level-1];
int c2=cc[i][j+(1<<(level-1))][level-1];
int mx=(a[c1]<a[c2])?c2:c1;
cc[i][j].push_back(mx);
}
}
}
firstly i have converted to a structure like the following:-
Example input:- 10 6 20 15 8
(b[i]-->stores the indices of factors of i)
b[2]--> 1,2,3,5
b[3]--> 2,4
b[5]--> 1,3,4
Now after implementing RMQ, it will be as follow:-
(cc[i][j][k] stores index of the largest element between b[i][j] and b[i][j+(2^k)-1])
cc[2][0]-->1,2,3,5
cc[2][1]-->1,3,3
cc[2][2]-->3
cc[3][0]-->2,4
cc[3][1]-->4
cc[5][0]-->1,3,4
cc[5][1]-->3
My Code
100 1
88 33 23 56 97 54 8 74 43 95 91 63 38 13 7 7 52 29 6 85 70 15 52 18 78 9 85 51 28 43 4 68 75 78 75 23 32 34 48 74 28 90 36 66 2 95 24 54 23 29 90 45 96 93 14 73 2 99 75 81 93 31 100 19 8 75 93 39 60 41 64 88 30 100 5 84 46 28 89 20 56 30 64 3 22 78 75 75 76 2 8 20 32 7 38 39 33 82 30 93
95 95 97
The output is -1 -1, but gcd(38, 95) = 19, so ans should be 38 1.
Replacing 'break' by 'continue' on line 75 gave AC :)

c++ rand() % 100 [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
im trying to fill an array with random 200 numbers that can very from 0-100. I get it populated except the last couple number are very odd.
here my code.
for (int i = 0; i < NUM_LIST_ELEMENTS; i++)
{
int j = rand() % 100;
list[i] = j;
}
my output comes out at follows
Original Arrays:
41 67 34 0 69 24 78 58 62 64 5 45 81 27 61 91 95 42 27 36 91 4 2 53 92 82 21 16 18
95 47 26 71 38 69 12 67 99 35 94 3 11 22 33 73 64 41 11 53 68 47 44 62 57 37 59 23 41
29 78 16 35 90 42 88 6 40 42 64 48 46 5 90 29 70 50 6 1 93 48 29 23 84 54 56 40 66
76 31 8 44 39 26 23 37 38 18 82 29 41 33 15 39 58 4 30 77 6 73 86 21 45 24 72 70 29
77 73 97 12 86 90 61 36 55 67 55 74 31 52 50 50 41 24 66 30 7 91 7 37 57 87 53 83 45
9 9 58 21 88 22 46 6 30 13 68 0 91 62 55 10 59 24 37 48 83 95 41 2 50 91 36 74 20
96 21 48 99 68 84 81 34 53 99 18 38 0 88 27 67 28 93 48 83 7 21 10 17 13 14-858993460
9 16 35 51 0 49 19 56 98 3 24 8 44 9 89 2 95 85 93 43 23 87 14 3 48 0 58 18 80
96 98 81 89 98 9 57 72 22 38 92 38 79 90 57 58 91 15 88 56 11 2 34 72 55 28 46 62 86
75 33 69 42 44 16 81 98 22 51 21 99 57 76 92 89 75 12 0 10 3 69 61 88 1 89 55 23 2
85 82 85 88 26 17 57 32 32 69 54 21 89 76 29 68 92 25 55 34 49 41 12 45 60 18 53 39 23
79 96 87 29 49 37 66 49 93 95 97 16 86 5 88 82 55 34 14 1 16 71 86 63 13 55 85 53 12
8 32 45 13 56 21 58 46 82 81 44 96 22 29 61 35 50 73 66 44 59 92 39 53 24 54 10 45 49
86 13 74 22 68 18 87 5 58 91 2 25 77 14 14 24 34 74 72 59 33 70 87 97 18 77-33686019
notice that last number in each array is really weird. Is there anything I can do to avoid this? btw this is two different arrays.
Thanks everyone that posted! I got it working!
You are reading one beyond the end of the array.
e.g. if you populate an array with 200 elements, you should write to and read from 0 to 199 not 0 to 200 or 1 to 200.
By the way - rand() % 100 will not make numbers from 0 to 100. It will make numbers from 0 to 99 only.
Also, as Randy Howard says (thanks), you can get a more even random generation by following the advice at http://www.azillionmonkeys.com/qed/random.html .
This is probably because there is something wrong with your code that prints the result. You might be looping from index 0 to 200, which has 201 items.
I counted your outputs and found there is 201 items, if the last 77-33686019 are actually 2 separate numbers.
If it's not that, you might have some printf/cout somewhere further down your code that actually prints some other value. To confirm this you can probably try printf ("\n"); right after your loop that outputs the array. If your negative number ends up on a different line, you'll know it's some other printf further down your code.
You might want to use int j = rand() % 101; instead so that you get 0 to 100. Your original code gives you the random range from 0 to 99.

Access values from Matrix in OpenCV

For example, I have a matrix M of size 10x10 and I have a column matrix ind of length 5
How can I assign A(ind,:) to a new matrix B in C++ with OpenCV?
Below is how I do in Matlab:
A = [ 41 8 33 36 22 14 38 43 18 4
46 49 2 2 20 34 13 13 42 3
7 48 43 14 39 33 26 41 30 27
46 25 47 3 40 9 35 13 28 39
32 41 34 5 10 6 45 47 46 47
5 8 38 42 25 25 48 18 15 7
14 22 38 35 23 48 28 10 38 29
28 46 20 16 33 18 7 13 38 24
48 40 33 48 36 30 8 31 20 1
49 48 9 2 38 12 13 24 29 17]
ind = [2; 8; 4; 6; 2]
B = A(ind, :);
B = [ 46 49 2 2 20 34 13 13 42 3
28 46 20 16 33 18 7 13 38 24
46 25 47 3 40 9 35 13 28 39
5 8 38 42 25 25 48 18 15 7
46 49 2 2 20 34 13 13 42 3]
Can anyone tell me how to do this in C++ with OpenCV without using for loop
There is no direct way to extract a random ordering of rows/columns without iterating in some way. The simplest method is to extract rows and push them into the target matrix one by one. Given you have your matrix A declared and its data set:
cv::Mat B;
B.push_back(A(cv::Range(2,3),cv::Range::all()));
B.push_back(A(cv::Range(8,9),cv::Range::all()));
B.push_back(A(cv::Range(4,5),cv::Range::all()));
B.push_back(A(cv::Range(6,7),cv::Range::all()));
B.push_back(A(cv::Range(2,3),cv::Range::all()));
should do what you want. This uses the overloaded operator()(cv::rowRange, cv::colRange) to extract the selected rows.
I don't think this is possible without using for loop but the fastest way of doing this is by using memcpy. You can see the complete code here

Regarding Standard Oxford Format for vlfeat sift

One of my upper classmates has given me a data set for experimenting with vlfeat's SIFT, however, her extracted SIFT data for the frame part contains 5 dimensions. An example is given below:
192
9494
262.08 749.211 0.00295391 -0.00030945 0.00583025 0 0 0 45 84 107 86 8 10 49 31 21 32 37 46 50 11 23 49 60 29 30 24 17 4 15 67 25 28 47 13 11 27 9 0 40 117 99 27 3 117 117 39 19 11 18 16 32 8 27 50 117 102 20 23 18 2 10 36 45 47 84 37 16 36 31 9 50 112 52 12 9 117 36 6 4 3 15 54 117 9 3 2 31 94 101 92 23 0 20 47 36 38 14 1 0 34 19 39 52 27 0 0 31 6 14 18 29 24 13 11 11 12 10 3 1 4 25 29 5 0 5 6 3 12 29 35 2 93 73 61 50 123 118 100 109 58 44 79 122 120 108 103 87 92 61 28 33 55 107 123 123 37 73 60 32 93 123 123 89 118 118 77 66 118 118 63 96 118 94 60 27 41 74 108 118 107 81 107 118 118 43 73 64 118 118 118 56 45 38 27 58
432.424 57.2287 0.00285143 -0.00048992 0.00292525 10 12 19 26 88 43 14 10 3 4 44 50 125 74 0 1 2 4 47 34 17 3 0 0 3 3 8 6 1 0 0 1 11 12 14 17 43 37 10 6 35 36 125 77 47 10 5 13 2 7 125 125 125 29 0 2 1 3 11 15 33 5 1 0 36 14 7 8 102 64 37 27 41 8 2 2 55 53 103 125 4 2 2 5 125 125 41 28 1 3 4 7 32 11 3 1 46 29 6 7 125 57 3 3 49 11 0 1 90 34 19 31 10 3 3 6 122 33 10 9 0 2 11 10 7 2 2 1 35 64 129 129 129 93 48 44 24 55 129 117 129 71 41 19 44 65 76 58 129 129 129 89 42 48 57 96 129 129 90 55 133 118 58 42 58 42 133 133 133 62 24 17 18 12 133 133 133 133 133 125 78 33 17 29 133 133 82 45 23 11 13 44
... // the list keeps on going for all keypoints.
This file is simply descriptors' data of an image. There are a few things I need to know:
what are the first two values '192' and '9494'?
what is the 5th value for the keypoint? vlfeat's sift normally gives out 4 values for key point's frame.
So I asked her what is this 5th dimension, and she pointed me to search for "standard oxford format" for sift feature.
The thing is I tried to search around regarding this standard oxford format and sift feature, but I got no luck in finding it at all. If somebody knows anything regarding this, could he please point me to the right direction?
192 represents the descriptor length ,9494 represent the Number of key-points you have in the file.
The other line consists of [WORD_ID] [X] [Y] [A] [B] [C]
X and Y is the feature centroid and A, B, C define the parameters of
the ellipse in the following equation A*(x-X)^2 + 2*B*(x-X)(y-Y) + C(y-Y)^2 = 1
You can check the official website for the formate Here
If you are using VLfeat package you can read here how to read the file in Oxford format.
If you are very curious how the file formate is read in VLfeat vl_ubcread function. Here is the code.