simple way to Change element of parameter - gams-math

I need to change the element of b (change 1 to 0 and 0 to 1 ) to get new parameter c(j). I want to use macro option, is it possible?
set j/1*100/;
parameter b(j) ,c(j);
*suppose b(j) initialized
c(j)=b(j);
loop(j,
if(c(j)=1,
c(j)=0;
else
c(j)=1;
);
Thanks!

It is possible to do this in a macro. However, if you just want to toggle 0/1, you can also simply use the not operator. Look at this modified version of your code:
set j/1*100/;
parameter b(j) ,c(j);
* Fill with random data
b(j) = uniformInt(0,1);
* Note: This is actaully not necessary; you could also use b directly below
c(j)=b(j);
c(j) = not c(j);

Related

assign value at specific list index in robot framework

I have a list:
#{IFUP} 10 20
I want to modify only one of those values, e.g:
${IFUP}[${idx}]= Set Variable 30
where $idx is 0
This produces No keyword with name ''${IFUP}[${idx}]='. Same happens with direct ${IFUP}[0] assignment.
RobotFramwork version is 3.1 (list syntax is a bit different).
I would be happy with a variable variable solution like: ${IFUP_${idx}}= but this produces the same error.
Suggestions?
You can use the 'Set List Value' keyword from Collections library.
In your case, it should be
Set List Value ${IFUP} 0 30
http://robotframework.org/robotframework/latest/libraries/Collections.html#Set%20List%20Value
Please check below code:
List_at_place_change
#{IFUP} Create List 10 20
Log ${IFUP[0]}
Set List Value ${IFUP} 0 30
Log ${IFUP}

Possible to store a value in variable in SPSS?

Is is possible in SPSS to store a value in a variable (not a variable created in a data set)?
For example I have a loop for which I want to pass the value 4 to all the locations in the loop that say NumLvl.
NumLvl = 4.
VECTOR A1L(NumLvl-1).
LOOP #i = 1 to NumLvl-1.
COMPUTE A1L(#i) = 0.
IF(att1 = #i) A1L(#i) = 1.
IF(att1 = NumLvl) A1L(#i) = -1.
END LOOP.
EXECUTE.
You can do this using DEFINE / !ENDDEFINE SPSSs Macro Facility, for example:
DEFINE !MyVar () 4 !ENDDEFINE.
You can then use !MyVar as a substitute for 4 wherever in your syntax you wish.
See DEFINE / !ENDDEFINE documentation for further notes.

Reverse MS-Access Format Function

I have a field within an Access 2007 database which contains either a 0 or a 1.
When displaying a view, I need to format the field as Yes/No.
My issue is that I can't use FORMAT(Field,"Yes/No") as the 1 and 0 are the wrong way round i.e.:
0 = No 1 = Yes is how the format function works.
1 = No 0 = Yes is how my data is formatted.
Is there anyway to reserve or manipulate the FORMAT function in a way that when a query is run, the query will display my Yes/No the correct way round?
FORMAT(ABS(Field-1), "Yes/No")
This works because ABS(1-1) = 0 and ABS(0-1) = 1. In other words your 0 -> 1 and 1 -> 0, so it changes the number to have the "right" value (as far as MS-Access is concerned) before using the format function.

Using CONTAINS with variables sql

Ok so I am trying to reference one variable with another in SQL.
X= a,b,c,d (x is a string variable with a list of things in it)
Y= b ( Y is a string variable that may or may not have a vaue that appears in X)
I tried this:
Case when Y in (X) then 1 else 0 end as aa
But it doesnt work since it looks for exact matches between X and Y
also tried this:
where contains(X,#Y)
but i cant create Y globally since it is a variable that changes in each row of the table.( x also changes)
A solution in SAS would also be useful.
Thanks
Maybe like will help
select
*
from
t
where
X like ('%'+Y+'%')
or
select
case when (X like ('%'+Y+'%')) then 1 else 0 end
from
t
SQLFiddle example
In SAS I would use the INDEX function, either in a data step or proc sql. This returns the position within the string in which it finds the character(s), or zero if there is no match. Therefore a test if the value returned is greater than zero will result in a binary 1:0 output. You need to use the compress function with the variable containing the search characters as SAS pads the value with blanks.
Data step solution :
aa=index(x,compress(y))>0;
Proc Sql solution :
index(x,compress(y))>0 as aa

Increment an integer

Sometimes ABAP drives me crazy with really simple tasks such as incrementing an integer within a loop...
Here's my try:
METHOD test.
DATA lv_id TYPE integer.
lv_id = 1.
LOOP AT x ASSIGNING <y>.
lv_id = lv_id+1.
ENDLOOP.
ENDMETHOD.
This results in the error message Field type "I" does not permit subfield access.
You already answered the question yourself, but to make things a bit clearer:
variable + 1
is an arithmetic expression - add 1 to the value of the variable.
variable+1
is an offset operation on a character variable. For example, if variable contains ABC, variable+1 is BC.
This can be especially confusing when dealing with NUMCs. For example, with variable = '4711', variable + 1 is evaluated to 4712, whereas variable+1 is '711' (a character sequence).
The error you saw occurred because it's not possible to perform the index operation on a non-character-like variable.
You mean like:
ADD 1 to lv_id.
By the way, when you loop over an internal table, SY-TABIX has the loop counter.
Uh, I got it.
It's the f****** spaces...
lv_id = lv_id + 1
works...
Simple
DATA : gv_inc type I .
place this statement in loop
gv_inc = gv_inc + 1 .
from SAP NetWeaver Version 7.54 you can also use:
lv_id += 1.
Instead of
lv_id = lv_id + 1.
Happy coding!
If you are going to increment every loop cycle than you can directly get the table size.
describe table x lines data(lv_id). "Out side of the loop.