mardi 1 décembre 2020

Loop for checking multiple conditions in SAS with or without MACROS

I am new to SAS and read SAS if statement in do loop and I am still confused on how to solve the loop problem. I also have no idea to use Macro here.

The code is given belòow:

if DIA_PRINCd=001 or DIA_UNOd=001 or DIA_DUEd=001 or DIA_TREd=001 or DIA_QUATTROd=001 or DIA_CINQUEd=001 or
DIA_PRINCd=002 or DIA_UNOd=002 or DIA_DUEd=002 or DIA_TREd=002 or DIA_QUATTROd=002 or DIA_CINQUEd=002 or
--------------------
---------------------
DIA_PRINCd=142 or DIA_UNOd=142 or DIA_DUEd=142 or DIA_TREd=142 or DIA_QUATTROd=142 or DIA_CINQUEd=142 ;

run;

May I know how to use loop in SAS for this problem?

What's aarch64's way to conditionally load/store?

I know that armv7 can use condition codes for load/store, like ldrne/streq. But A64 does not allow instructions to be conditionally executed. so how can i archive this in arm64:

ands    tmp1, dstend, 7 # set nzcv flag with ands
# if not zero, ldr w6, [srcend, -4]!, str w6, [dstend, -4]!
# else, do nothing and goes on
...

Python: Input accepts two+ arguments, but doesn't accept a single argument

My input accepts the input for two+ arguments, but doesn't accept when I need only a single argument; my code is suppose to be a "command line prompt" that is suppose to accept input from the user to create router interfaces and connections. I use argNum = len(delimitedInput), which is my input, and have the code follow based on the if statements. However, the if argNum == 1 is not working, while the other are working perfectly. Any help here is appreciated and here's my code below:

while 1:
    try:
        message, address = clientSocket.recvfrom(8192) # Buffer size is 8192. Change as needed.
        if message:
            print (address, "> ", message.decode())
    except:
        pass
 
    input = getLine();
    if(input != False):
        #output input
        print("input is: ", input)
        #split the input into delimitedInput 
        delimitedInput = input.split(' ') 
        #argNum is number of arguments the user typed 
        argNum = len(delimitedInput)
        command = delimitedInput[0] 
        print("The number of arguments is ", argNum) 
        #TODO: Accepting one argument 
        if argNum == 1:
            (command) = delimitedInput[0] 
            if command == "test":
                print("test")
            if command == "status":
                print("The router is listening and accepting connections to the following ports: ")
                print(mainlist)
                print("The router's name is ", routername)
            if command == "routerconnect":
                print("The following routers are connected to this router with the cost: ")
                print(connectionlist) 
        #Accepting two arguments
        if argNum == 2:
            port = delimitedInput[1] 
            (command, port) = delimitedInput
            #listenport + acceptport built into one command with a space to setup the listening port
            if command == "mainport":
                incomingPort = int(port)
                clientSocket.bind(('', incomingPort)) 
                mainlist.append(incomingPort)
                print("You are now listening and accepting connections to the this port:")
                print(mainlist)
                routername = "R" + str(incomingPort) 
                print("The router name is also now: ", routername)
        #Accepting three arguments
        if argNum == 3:
            port = delimitedInput[1]
            port2 = delimitedInput[2] 
            if command == "remote":
                #port = remote host address
                rmaddress.append(port)  
                #port2 = remote port 
                rmport.append(port2)
                remoteAddressAndPort = (port, int(port2))
                print("Command: ", command)
                print("Remote host address: ", port)
                print("Remote port: ", port2)
                clientSocket.sendto(input.encode(), remoteAddressAndPort)
        #Accepting four arguments 
        if argNum == 4:
            port = delimitedInput[1]
            port2 = delimitedInput[2]
            message = delimitedInput[3]  
            (command, port, port2, message) = delimitedInput 
            #Sending a message to other UDP chat hosts using the remoteport command
            if command == "send":
                #port = remote host address; this HAS TO BE 127.0.0.1 FOR SOME REASON 
                rmaddress.append(port)  
                #port2 = remote port 
                rmport.append(port2)
                remoteAddressAndPort = (port, int(port2))
                print("Command: ", command)
                print("Remote host address: ", port)
                print("Remote port: ", port2)
                print("Message: ", message) 
                clientSocket.sendto(input.encode(), remoteAddressAndPort)
            #setting up router cost
            if command == "cost":
                #port = remote host address, which has to be 127.0.0.1
                #port2 = remote port you want to connect to 
                #message = cost to move to that router
                message = int(message)
                port2 = ("R" + port2)   
                #Add to the connection/cost list
                connectdiction.append(str(port2) + " " + str(message))
                #Add to the "what is this connected to" list"
                connectionlist.append(port2)   
                print("Command: ", command)
                print("Remote host address, which has to be 127.0.0.1: ", port)
                print("Remote port, which should be the just the number: ", port2)
                print("Cost to connect to this router: ", message) 

IF ELSE in postgresql function

I am trying to create a function which is as follows

create function public.getSomething(
        value1 integer
    )
      returns table (
             id integer,
             name varchar(20)
    
              ) as
    $$
    BEGIN
    
        IF value1 = 0 THEN
        
            select a.id, b.name from table1 a inner join table2 b on a.Something = b.Something where 
            a.column = something and b.column = something;
            
        END IF;
    
        IF value1 = 1 THEN
        
            select a.id, b.name from table1 a inner join table2 b on a.Something = b.Something where 
            a.column = something and b.column = something;
            
        END IF;
    
    END;
            
    $$ language SQL;

But when I am trying to Create, I am getting the following error

ERROR:  syntax error at or near "if" 

I tried changing the Language from SQL to plpgsql. But this time I am getting

Error: query has no destination for result data
Hint: if you want to discard the results of a select use perform instead

then I replaced the Select with Perform. This time the function is created but when I am calling it There is no result!!

What am I doing wrong? Is there any alternative? I am Using postgres version 12.3

If/elif condition not triggered when it should in recursive function

I am trying to write code to find whether a given number is odd or even using recursion in Python.

When I execute my code, the recursive function descends down to 0 correctly but then doesn't halt, and keeps going with negative values. I expect it to stop when it reaches 0.

How to make sure the function returns after it reaches zero?

My code:

def odeven(n):
    if n%2 == 0:
        print("even no. : ",n)
    elif n%2 != 0:
        print("odd no. : ",n)
    elif (n == 0):
        return 0
        
    return odeven(n-1)

result = odeven(10)

print("result odd ={}".format(result))

Can't get my conditional to check input value for str or int and ignore if statement (Python 3.9)

Trying to write a simple if, elif statement. I prompt the user for an input and: if input is an int(), run the if seconds => statement and begin countdown. elif input is a str(), print to the user to input an int().

print("We're ready captain! How many seconds until launch?")

seconds = input()

isInputString = type(seconds) == str #yields True if seconds == str()

if isInputString == True: #tell the user to try again
    print("I need a number Captain!")
    seconds = input() #prompt a second input

else: #else it wasn't a str() and to proceed on with script
    pass

Currently the script will prompt for a second input even if a int() was entered.

Is this due to how I entered my if - else statement?

I feel like it should resort to else - pass if an int() is entered but it still prompts the 2nd branch input() even though isInputString == False.

Simplify if-statement

I have a table which has several columns containing the answers to yes / no questions, with a final column giving the answer to whether a given row contains a "Vesentleg anvendelse" according to this flow chart.

enter image description here

I created the following if-formula to determine this, but I feel it is a bit clunky - is there any way to simplify it?

=IF([@[Myndighet-, lokal-, sentralkrav?]]="Ja";
    "Ja";
    IF([@[Stort potensial?]]="Ja";
        IF([@[Økonomisk bærekraftig?]]="Ja";
            "Ja";
            "Nei");
        IF([@[Vanskelig å gjennomføre]]="Nei";
            IF([@[Økonomisk bærekraftig?]]="Ja";
                "Ja";
                "Nei");
            "Nei")
        )
    )

The table itself looks like this:

enter image description here