Operation result with one of the variables null (empty) - sas

I am converting SAS code to C# code and I don't have platform to run SAS code, what I have only source code, and I have line of the code in SAS where one of the variables is empty and another is not and I would like to know what would be result of y in following operation.
x = .
y = 5 - x
x is empty (null)
Please advice.
Thanks a lot in advance for your help.

I believe the result of y will be . (empty)
When you perform an operation with an empty(null) variable the result is null.

Related

Taking first observation of a series as unobserved parameter in non-linear regression

I am trying to estimate the following equation in Stata using non-linear least squares command nl:
π_t= π_t_e+ α (y-y*)
where π_t_e= γ * π_t-1_e+(1-γ) π_(t-1)
π_t, y and y* are already given in the dataset, π_t_e is created from π_t using second equation. There are 34 observations in the dataset. The first observation of π_t_e i.e. π_1_e is treated as an unobserved parameter, along with gamma and alpha.
I wrote the following code but it is not working:
local s "{pi_1_e}"
local s "({gamma}*L.`s'+ (1-{gamma})*L.pi)"
nl ( pi = (`s') + {alpha}*(y-y*))
The first line of the code assigns pi_1_e to s. But the second line replaces s with
({gamma}*L.`s'+ (1-{gamma})*L.pi)
For _n==1, L.s doesn't exist. Hence, it is replaced with a missing value and all other 33 observations are assigned missing values. I wish to run second line of the code from _n>=2. But if condition doesn't work with local macro.
Can someone help me understand how to resolve this?

Is there even a slight possibility to process two lists in one single list comprehension line?

I would like to ask if there's a possibility to process more than one list in just a single line with list comprehension? I'm using Python 2.7 .
Here is what the code looks like:
n=[1,2,3,4,5,6,7]
m=[1,7]
c=[]
for x in m:
if x in n:
c.append(x)
n.pop(n.index(x))
print n
print c
The output is:
[2,3,4,5,6]
[1,7]
Now I'm wondering if I could turn the code (line 5 to line 8) into a single line using a list comprehension?
I would appreciate your advice. Let me know if my question has a duplicate. Thank you very much.
You can do it this way since popping a value from the list returns the value
n=[1,2,3,4,5,6,7]
m=[1,7]
c=[n.pop(n.index(x)) for x in m if x in n]
print n
print c
n=[1,2,3,4,5,6,7]
m=[1,7]
print set(n)-set(m)
> [2,3,4,5,6]
Assign the sets to their own variables if you need to perform additional operations. Converting to a set will take some time on a big list but then membership, subtraction, union or intersection operations should be very fast.

Nesting AND NOT ISBLANK with MULTIPLE IFs

I can't find an example close enough to this one on StackOverflow so here goes:
I want to return a message "Type?" if cell X is blank and cell Y has any text. But I'm trying to nestle it into an existing set of IFs.
Existing :
=IF($G241="Evo";M241*L241;IF($G241="Free";M241*L241;IF($G241="GN";M241*L241))))
Nestling this into the above:
=IF(AND(NOT(ISBLANK($J234));ISBLANK(G234));"Type?";"OK")
I tried this but it returns FALSE, maybe due to the AND I'm using, which I need since I'm creating a return based on two cells two cells.
=IF($G240="Evo";M240*L240;IF(AND(NOT(ISBLANK($J240));ISBLANK(G240);"Type?";"OK");IF($G240="Free";M240*L240;IF($G240="GN";M240*L240))))
getting Error:
AND expects boolean values. But 'Type?' is a text and cannot be coerced to a boolean.
IF(and(isblank(cell x),iferror(isstring(cell y),false)),"Type?","OK")
That should do it for you I think. you will need to replace cell x and cell y with the appropriate references. The iferror statement is there to catch what happens when evaluating a blank cell y.
The problem with this formula
=IF($G240="Evo";M240*L240;IF(AND(NOT(ISBLANK($J240));ISBLANK(G240);"Type?";"OK");IF($G240="Free";M240*L240;IF($G240="GN";M240*L240))))
is you are trying to check G240 for different values when it cant. Lets simplify your formula. We will replace your empty cell check with FORMULA 1
=If($G240="EVO", Do True Condition, Do Formula 1, IF(G$240=Free, Do Free True Condition, Do Free False Condition)
The problem is since you already did something (Formula 1) when G240 = "EVO", you cant start another check on what G240 after the fact with the way you have embedded your formula. a batter way of thinking of it is how to do a second check when G240="EVO" is false. Remember the general format of an if statement is:
IF(CONDITION,True Result, False Result)
There are only 3 things that go into an if statement. you tried putting in 3.
Try rearranging to this:
=If($G240="EVO", Do True Condition, IF(SOME CHECK to determine DO FOMULA 1 or CHECK for G240 = FREE, Do Formula 1, IF(G$240=Free, Do Free True Condition, Do Free False Condition)))
Basically break down what you want to check for in G240 and do it in sequence with your IF statement. Right now with what you have written, I cant tell how you want to determine if you want to run your formula 1 or if you want to check if G240="free" since you have two different outcomes if G240="Free"/
OK I think i found the issue. The IF(AND(NOT(ISBLANK works on it's own since there are no other IFs in the formula. I do want to test two different cells for text(letters) in order to show a warning if one cell was blank while the other not. But as soon as you insert the (AND into a string of multiple IFs it doesn't work.
Simply removing the (AND was all I needed to do. Another way to achieve a test for more than one blank cell was to simply add multiple IF(ISBLANKs.
EG: =IF(ISBLANK(A1)+IF(ISBLANK(A2)>2;condition true;condition false)
ForwardEd thanks very much for your help!
Regards

Split sample in Stata

I have a variable X containing 3100 values.
I need to split X into variable Y and Z. Y containing 1500 first values of X and Z containing the rest of X.
I'm not sure whether it works with
split X
or any other code
Did you try it?
split is for splitting strings and for splitting them into parts according to their contents.
You appear to want something like separate X, by(_n <= 1500) followed by renaming if you wish. Two generate statements would also work fine.

Simplifying SAS code (if statement) using macro

I have a variable x with values from 1 to 390. I need to group it in intervals of 5,
in other words
if x<6 then interval=1;
if x>5 and X<11then interval=2;
if x>10 and x<16 then interval=3; etc.
What is a shorter way of writing this code without having to repeat this if statement all the way to x=390?
This is really a bit too basic, but ok.
interval = ceil(x/5);