So I have 3 user-provided values, the first is their "total_income", the second value is either "part_time" or "full_time", and the last value is "family_size".
I'm trying to write code in LUA that takes these values and evaluates them to assign a value called "fee".
I have an excel file that gives me "fee" values for both "full_time" and "part_time", and those depend upon what "total_income" is entered.
The problem I am having is, I don't know how to incorporate the user's provided values of "part_time" and "family_size"
I hope this makes sense, if not please don't hesitate to email me at ochow0401#gmail.com, or PM me here. Any help would be highly appreciated.
Whoever can steer me in the right direction first, gets lunch on me ;)
I was able to successfully compare the user-provided "total_income" against the excel file to see where it falls in the income range. Based on this index I am able to see what "fee" value to assign. The code I provided below successfully sets the "fee" for the users "total_income", but how would I do a check for whether the user inputted "part_time" or "full_time" within a loop?
part_time_fee = 0
full_time_fee = 0
part_time = {31,38,45,53,68,76,85,94,104,113,123,134,145,156,159,161,164,167,178,181,184,187,190,193,196,199,203,206,209,212,215,218,221,227,234,240,246,252,259,265
}
full_time = {61,75,90,106,135,152,170,207,226,246,267,289,311,317,322,328,334,355,361,367,373,380,386,392,398,405,411,417,423,429,436,442,454,467,479,492,504,517,529
}
family_size_1_or_2 = {2451,2514,2577,2640,2703,2766,2829,2892,2955,3017,3080,3143,3206,3269,3332,3395,3457,3520,3583,3646,3709,3772,3835,3897,3960,4023,4086,4149,4212,4275,4337,4400,4463,4589,4715,4840,4966,5092,5218,5343
}
for i = 1, 40, 1
do
if family_size_1_or_2[i] >= answers.calc_total_income then
answers.fam_fee = part_time[i]
break
end
end
https://imgur.com/SHHqC2L
That is the first 15 rows of the excel sheet I was provided.
I am to take the users inputs, "total_income", "family_size", and "part_time" or "full_time". Then I am to give it it's corresponding "fee" value.
So if a user were to enter these values:
total_income = 3000
family_size = 2
full_time
then
fee = 226
Iam developing a report where I need to provide special effects on 1st few columns. How can I color code or provide 3D effect for first five rows of a table in SSRS? Also, count of values in these columns?
For example:
My date count
A 3
B 4
C 1
D 1
E 5
F 6
G 7
Now, I should color rows start from A to E and get total count of that ( e.g. 14 in this case)
How can I I acheive this?
While Strawberryshrub's answer would probably work just fine, there's an easier way that can get you the same result. You should be able to use the SSRS function RowNumber to indicate which rows should be colored. Try the following expression in the background color property for that row.
=IIF(RowNumber(Nothing) < 6, "Green", "No Color")
Also, for the count that you need, you should be able to use a similar pattern.
=SUM(IIF(RowNumber(Nothing) < 6, Fields!count.Value, 0))
One possible option is to cathegorize your first column with an calculated field:
'Name: CustomCathegory
=IIF(Fields!MyDae.Value = "A" Or
Fields!MyDae.Value = "B" Or
Fields!MyDae.Value = "C" Or
Fields!MyDae.Value = "D" Or
Fields!MyDae.Value = "E", "Cathegory1", "CathegoryElse")
Now you can use the row coloring (font or background) and use the following expression:
=IIF(Fields!CustomCathegory = "Cathegory1", "Blue", "Black")
You can also sum by CustomCathegory (textbox outside the detail section)
=Sum(IIF(Fields!CustomCathegory = "Cathegory1", Fields!Count.Value, 0))
or group your table by CustomCathegory and add header or footer with the sum per CustomCathegory
I just learned about the "do" loop today and would like to try using it for data entry in SAS. I have tried most examples online, but I still cannot figure it out.
My dataset in an experiment with 6 treatments (1 to 6) using 2 sets of cues, 3 each, Visual and Audio. There's lag measured in seconds, which are 5, 10, and 15, which there are 2 sets.
Basically it looks like this:
Table
The entries I want are:
1. Obs_no, ranging from 1 to 18 (total of 18 observations, this allows me to easily delete outliers with an IF THEN)
2. Treatment type, which are Auditory and Visual.
3.Treatment number, 1 to 6, 3 sets.
4. Lag, 5, 10 or 15.
5. And the data itself
So far, my code makes 2 and 5 possible, it also makes the rest possible with an IF THEN statement and input statement, although I assume there's a way easier method:
data AVCue;
do cue = 'Auditory','Visual';
do i = 1 to 3;
input AVCue ##;
output;
end;
end;
datalines;
.204 .167 .202 .257 .283 .256
.170 .182 .198 .279 .235 .281
.181 .187 .236 .269 .260 .258
;
Lag and the rest was made possible using an IF THEN statement and the crude method of input:
data AVCue;
set AVCue;
IF i=1 THEN Lag=5;
IF i=2 THEN Lag=10;
IF i=3 THEN Lag=15;
input obs_no treatment;
cards;
1 1
2 2
3 3
4 4
5 5
6 6
7 1
8 2
9 3
10 4
11 5
12 6
13 1
14 2
15 3
16 4
17 5
18 6
;
proc print data=AVCue;
run;
The IF THEN should be fine, but the input statement here is just in my opinion counterproductive, and defeats the purpose of using loops, which is to me, to save time. If done this way, I might as well just put the data into excel and import it, or type everything out with ample copy and paste of the text in the
input obs_no treatment;
cards;
section.
My coding knowledge is basic, so sorry if this question sounds silly, I want to know:
1. How would I make a list of numbers using the "do" loops in SAS? I've made several attempts and all I get is a list containing the next number. I know why this happens, the loop counts to x and the value assigned would just be x. I just don't know how to get around that. Somehow this didn't happen in the datalines section, I guess SAS knows there's 18 numbers and the entry i is stored accordingly... or something?
2. How would I go about assigning in this case, the numbers 1 to 6 to each entry?
Thanks!
It is certainly much easier to read in the actual dataset instead of having to impute some of the variables based on the order the values have in the source data. You might be able to combine a SET statement and an INPUT statement in the same data step and get it to work, but it is probably NOT worth the effort. Just make two datasets and merge them.
Looking at the photograph you posted it looks like TREATMENT is not an independent variable. Instead it is just a label for the combination of CUE and LAG. To make it cycle from 1 to 6 just reset it back to 1 when it gets too large.
data AVCue;
do cue = 'Auditory','Visual';
do lag= 5, 10, 15 ;
treatment+1;
if treatment=7 then treatment=1;
obsno+1;
input AVCue ##;
output;
end;
end;
datalines;
.204 .167 .202 .257 .283 .256
.170 .182 .198 .279 .235 .281
.181 .187 .236 .269 .260 .258
;
You can get in trouble if you just let SAS guess at how you want to define your variables. For example if you change the order of the CUE values do cue = 'Visual','Auditory'; then SAS will make CUE with length $5 instead of $8. Add a LENGTH statement to define your variables before you use them.
length obsno 8 treatment 8 cue $8 lag 8 AVCue 8 ;
This will also let you control the order they are created in the dataset.
If you really did already have a SAS dataset and you wanted to add a variable like TREATMENT that cycled from 1 to 6 (or really any DO loop construct) then could nest the SET statement inside the DO loop. Just remember to add the explicit OUTPUT statement.
data new ;
do treatment=1 to 6 ;
set old;
output;
end;
run;
I have a vector of 126 elements which is usually correctly sorted; however, I always sort it to make sure everything is okay.
The problem is that: when the array is already sorted, performing a sort would destroy the original values of the array.
I attached the array in a csv file and executed the script below, where I insert the vector in the first column of 'a' then sort it in the second then check for any differences in the third column.
a = csvread('a.csv')
a(:,2)=sort(a(:,1))
a(:,3)=a(:,2)-a(:,1)
result=sum(a(:,3).^2)
You could easily see that the first two columns aren't identical, and the third column has some none zero values.
Syntax for array
a = [17.4800
18.6800
19.8800
21.0800
22.2800
23.4800
24.6800
25.8800
27.0800
28.2800
29.4800
30.6800
46.1600
47.3600
48.5600
49.7600
50.9600
52.1600
53.3600
54.5600
55.7600
56.9600
58.1600
59.3600
74.8400
76.0400
77.2400
78.4400
79.6400
80.8400
103.5200
104.7200
105.9200
107.1200
108.3200
109.5200
110.7200
111.9200
113.1200
114.3200
115.5200
116.7200
132.2000
133.4000
134.6000
135.8000
137.0000
138.2000
139.4000
140.6000
141.8000
143.0000
144.2000
145.4000
165.4200
166.6200
167.8200
169.0200
170.2200
171.4200
172.6200
173.8200
175.0200
176.2200
177.4200
178.6200
179.9300
181.1300
182.3300
183.5300
184.7300
185.9300
187.1300
188.3300
189.5300
201.3700
202.5700
203.7700
204.9700
206.1700
207.3700
236.1100
237.3100
238.5100
239.7100
240.9100
242.1100
243.3100
244.5100
245.7100
246.9100
248.1100
249.3100
239.8400
241.0400
242.2400
276.9900
278.1900
279.3900
280.5900
281.7900
282.9900
284.1900
285.3900
286.5900
287.7900
288.9900
290.1900
277.8200
279.0200
280.2200
281.4200
282.6200
283.8200
285.0200
286.2200
287.4200
288.6200
289.8200
291.0200
291.0700
292.2700
293.4700
295.6900
296.8900
298.0900];
Your original vector is unfortunately not sorted. Therefore, sorting this result will obviously not give you what the original vector is supposed to be as the values that were out of order will become in order.
You can check this by using diff on the read in vector from the CSV file and seeing if there are any negative differences. diff takes the difference between the (i+1)th value and the ith value and if your values are monotonically increasing, you should get positive differences all around. We can see which locations are affected by finding values in the difference that are negative:
a = csvread('a.csv');
ind = find(diff(a) < 0);
We get:
>> ind
ind =
93
108
This says that locations 93 and 108 are where the out of order starts. Locations 94 and 109 is where it actually happens. Let's check out portions 90 - 110 of your vector to be sure:
>> a(90:110)
ans =
245.7100 % 90
246.9100 % 91
248.1100 % 92
249.3100 % 93
239.8400 %<-------
241.0400
242.2400
276.9900
278.1900
279.3900
280.5900
281.7900
282.9900
284.1900
285.3900
286.5900
287.7900 % 106
288.9900 % 107
290.1900 % 108
277.8200 % <------
279.0200
As you can see, locations 93 and 108 take a dip in numerical value, and so if you tried sorting the result then taking the difference, you'll notice that locations 1 up to 93 will exhibit a difference of 0, but after location 93, that's when it becomes unequal.
I'm frankly surprised you didn't see that they're out of order because your snapshot clearly shows there's a decrease in value on the left column towards the top of the snapshot.
Therefore, either check your data to see if you have input it correctly, or modify whatever process you're working on to ensure that it can handled unsorted data.
I have a longitudinal (person-level) dataset I am looking to for syntax for counting the number of times an event happened up to a certain point. More specifically I have 200 weeks of data (each week is coded 1-7, I'm only interested in weeks where the value is 5 or greater), But I am only interested in weeks that happened before a certain time point (the time point is different for each person but and captured under a single variable "eventweek"). So for person Y whose eventweek = 154, I want to know what percentage of weeks before week 154 (wks 1-153) where that person was coded a 5 or above. For person Z whose eventweek = 52, I want to know what percentage of weeks before week 52 (wks 1-51) for which that person was coded a 5 or above, and so on.
Any ideas on how to code this?
Try the following:
vector v = week1 to week200.
compute #z = 0.
loop #i = 1 to (eventweek -1).
compute #z = #z + (v(#i) ge 5).
end loop.
compute ew_perc = #z/(eventweek -1)*100.
exe.