what's the syntax error in these sas codes - syntax
data work.totalsales;
set work.monthlysales(keep = year product sales);
retain monthsales {12};
array monthsales {12};
do i = 1 to 12;
monthsales{i} = sales;
end;
count + 1;
monthsales{count} = sales;
run;
I submit these codes. But it appears to have syntax problems. But where?
Syntax issue is the array style name in the retain statement.
Runtime error possible because count is not initialized. If there are more than 12 records in "monthlysales" you will get an "array out of bounds" error on the 13th record.
Related
sparse matrix list .cat.codes invalid syntax error
i am having trouble with the piece of code below as part of an tutorial where we have to create a sparse matrix from 2 columns by first converting them into a list each. I am getting an unknown syntax error and really not sure how to resolve this. I would much appreciate any help please. Code: from pandas.api.types import CategoricalDtype customers = list(np.sort(grouped_purchased.CustomerID.unique())) # Get our unique customers products = list(grouped_purchased.StockCode.unique()) # Get our unique products that were purchased quantity = list(grouped_purchased.Quantity) # All of our purchases rows = grouped_purchased.CustomerID.astype(CategoricalDtype(categories = ['customers']).cat.codes Get the associated row indices cols = grouped_purchased.StockCode.astype(CategoricalDtype(categories = ['products']).cat.codes Get the associated column indices purchases_sparse = sparse.csr_matrix((quantity, (rows, cols)), shape=(len(customers), len(products))) Error: File "", line 10 cols = grouped_purchased.StockCode.astype(CategoricalDtype(categories = ['products']).cat.codes ^ SyntaxError: invalid syntax
SAS: creating benchmark period dummies (around event)
I want to do an event study and need some descriptives around the events I am testing with different window sizes. Let's assume I have a data set with 10000 observations (stocks, dates, measures) and merge them with an announcement data set. Now, I want to get a dummy variable that is always 0 except for parameters given by me: if date = announcement_date then; window_dummy at t-60 to t-11 = 1 or window_dummy at t-5 to t+5 = 1 I hope I described it appropriately and there is a way because there is no lead function or similar. Best M
From what I gather from this, you wish to have additional variable, which creates window (or binning) variable reaching x days to past and future; First we generate some test data. SAS dates are just numbers so: data begin; do i = 21040 to 21080; my_date= i; output; end; drop i; run; Next we calculate the window: %let act_date= 21060; %let min_date= %eval(&act_date - 5); /*5 days to past*/ %let max_date= %eval(&act_date + 3); /*3 days to future*/ Then it's left to generate the dummy variable: data refined; set begin; if &min_date <= my_date and my_date <= &max_date then dummy = 1; else dummy = 0; run; Now, one can calculate this all in single datastep, but maybe this is more informative way. Edit: you can specify windows as you please. In your case you could have: min_date1= %eval(&act_date - 60); max_date2= %eval(&act_date - 11); .... Then just add them to the if clause with or operator.
How to compare two tuples in PIG?
I want to filter the records of data set A whose flight_delay_time is less than some specific values(x). But I will get the value of x from another pig query which is a tuple in the sense x is a tuple. But using the following statement is throwing an error: B = FILTER A by flight_delay_time < x; dump B; The data in file A is in the following way; ravi,savings,avinash,2,char,33,F,22,44,12,13,33,44,22,11,10,22,26 avinash,current,sandeep,3,char,44,M,33,11,10,12,33,22,39,12,23,19,35 supreeth,savings,prabhash,4,char,55,F,22,12,23,12,44,56,7,88,34,23,68 lavi,current,nirmesh,5,char,33,M,11,10,33,34,56,78,54,23,445,66,77 Venkat,savings,bunny,6,char,11,F,99,12,34,55,33,23,45,66,23,23,28 the value of x = (40) which is stored as a tuple. the last column in the above data denotes the flight_delay_time. I am extracting the value of X in the following way. following is the data stored in C_CONTROL_BATCH.txt 25 35 40 15 I used following code to extract the value of X. control_batch = LOAD 'C_CONTROL_BATCH.txt' AS (start:int); variable = ORDER control_batch BY start DESC; X = LIMIT starttime 1;
Here is the solution: INPUT We have two input files: airlinesdata.txt - Having the rawdata ravi,savings,avinash,2,char,33,F,22,44,12,13,33,44,22,11,10,22,26 avinash,current,sandeep,3,char,44,M,33,11,10,12,33,22,39,12,23,19,35 supreeth,savings,prabhash,4,char,55,F,22,12,23,12,44,56,7,88,34,23,68 lavi,current,nirmesh,5,char,33,M,11,10,33,34,56,78,54,23,445,66,77 Venkat,savings,bunny,6,char,11,F,99,12,34,55,33,23,45,66,23,23,28 x.txt - Having data from where we get the values of x - 20 30 35 38 37 40 29 flight_delay_time column is last column in below relation and of type int. Note - If you don't declare it here the program with thrown an exception that it cant cast from byterarray to int when you filter in the end. rawdata = LOAD 'airlinesdata.txt' USING PigStorage(',') AS (field1:chararray,field2:chararray,field3:chararray,field4:chararray,field5:chararray,field6:chararray,field7:chararray,field8:chararray,field9:chararray,field10:chararray,field11:chararray,field12:chararray,field13:chararray,field14:chararray,field15:chararray,field16:chararray,field17:chararray,flight_delay_time:int); x_data = LOAD 'x.txt' USING PigStorage() AS (x_val:int); order_x_data = ORDER x_data BY x_val desc; max_value = LIMIT order_x_data 1; Here we are again casting the value to int for the filter condition to work. max_value_casted = FOREACH max_value GENERATE $0 as (maxval:int); Finally we can issue the filter query to get the results. Note how the maxval is accessed below by using the . operator from the max_value_casted relation. output_data = FILTER rawdata BY flight_delay_time < max_value_casted.maxval; DUMP output_data; OUTOUT - Values smaller than max value of X (40) (ravi,savings,avinash,2,char,33,F,22,44,12,13,33,44,22,11,10,22,26) (avinash,current,sandeep,3,char,44,M,33,11,10,12,33,22,39,12,23,19,35) (Venkat,savings,bunny,6,char,11,F,99,12,34,55,33,23,45,66,23,23,28) Hope it helps :)
SAS Proc means w/ completetypes preloadfmt not outputting 'other' group from user format
I'm doing the following to get an output table that includes 0 obs rows from a specified format. The output result works for all defined format categories EXCEPT the 'other' category, which in this case is the "null weight" of a scorecard. proc format; value var03f LOW - 75 = '79' 75 <- HIGH = '39' OTHER = '76' ; run; proc means data=thismonth completetypes noprint nway; class &thisvar./PRELOADFMT ; by ScoreDate; output out=way5(rename=(_freq_=count) keep=ScoreDate &thisvar. _freq_ _STAT_ where=(_STAT_ = "N")); run; proc print data=way5 l noobs; var ScoreDate &thisvar. count; run; Any ideas why the catch all isn't showing up? Thanks,
If you want to summarize missing class levels you must include the missing option.
Oracle Apex get Multiple results from checkboxes
DB = Oracle 11g Apex = 4.2.6 In the form I have various items which all work great. However I now have a set of check boxes(:P14_DAYS) one for each day of the week. What I need to do is get all records between :P14_START_DATE :P14_END_DATE, but only within the days select that's checked. Below is also a sample of the DATE_SETS table http://i.stack.imgur.com/YAckN.png so for example dates 01-AUG-14 - 5-AUG-14 But only require Sundays AND Mondays date would bring back 2 refs. BEGIN UPDATE MD_TS_DETAIL SET job_for = :P14_JOBFORTEM, job_type_id = :P14_JOB_TYPE_VALUE, account_id = :P14_ACC_VAL, qty = :P14_HRS, rio = :P14_RIO, post_code = :P14_POSTCODE WHERE id IN (SELECT D.id FROM MD_TS_MAST M LEFT JOIN MD_TS_DETAIL D ON M.mast_id = D.md_id LEFT JOIN DATE_SETS ON ms_date = dt WHERE eng_id = :P14_ENG_VAL AND ms_date BETWEEN :P14_START_DATE AND :P14_END_DATE AND DATE_SETS.col_day = ANY instr(':'||:P14_DAYS||':',Return) END; Any help would be much appreciated .
I found this example: http://docs.oracle.com/cd/B31036_01/doc/appdev.22/b28839/check_box.htm#CHDBGDJH As I can understand, when you choose some values in your checkbox list, item :P14_DAYS receives value, that contains return values of chosen elements of the LOV with delimiters. Then you need to replace this string in your query AND DATE_SETS.col_day = ANY instr(':'||:P14_DAYS||':',Return) with AND instr(':'||:P14_DAYS||':', ':'||DATE_SETS.col_day||':') > 0 Here function instr searches substring DATE_SETS.col_day in string :P14_DAYS. It returns position of substring if substring was found or 0, if not found. Then you compare result of function with 0, and if result > 0, it means that DATE_SETS.col_day is among selected values.