Giter Club home page Giter Club logo

hello-world's Introduction

hello-world

SAS, R, Python

SAS

/********** Create Database db1 with String 'Hello World' */
data db1;
    ********** Format Variable String as character with lenght 11;
    format STRING $11.;
    STRING="Hello World";
    ********** Output in SAS log;
    put STRING;
    ********** Output in db1;
    output;
run;

title1 "Hello World";
proc print data=db1 noobs;
run;

SAS Macro

%macro Hello(MYWORD);
;/********** Create Database db1 with String 'Hello World' */ 
data db1;
    %********** Format Variable String as character with length 40;
    format STRING $40.;
    STRING=&MYWORD;
    %********** Output in SAS log with %put;
    %put &MYWORD;
    %********** Output in db1;
    output;
run;

title1 "Hello World";
proc print data=db1 noobs;
run;
%mend Hello;

%Hello("Hello World (generated with SAS Macro)");

SAS Macro with Loop

* Macro for printing Hello World n-times (and Output in SAS log);
%macro MyLoop(NumLoop=, Output=Y);
    %********** Declare iterator as local;
    %local I;

    %********** Upcase Output;
    %let Output=%upcase(&Output);

    %********** If Parameter Output is Y = Yes:;
    %if &Output=Y %then %do;
        %********** Loop;
        %do I=1 %to &NumLoop;
            %put "Hello World &I"; %* Output in SAS Log;
        %end;
        %end;

    %********** If Parameter Output is not Y;
    %else %do;
        %put "Output is not Y"; %* Output in SAS Log;
    %end;
%mend MyLoop;
 
%MyLoop(NumLoop=8, Output=y);

* NOTE: Declare all variables within macro as %local, avoid using %global variables;
* NOTE: Macro parameters are always local to the macro that defines them;

R

# Define String
string <- "Hello World"
# print
print(string)
# or
cat(string, "\n")

R Function

hello <- function(string) {
  cat(string, "\n")  
}

hello("Hello World (generated with R Function)")

R Function with Loop

# Function for printing Hello World n-times (if output = TRUE)
hello <- function(numloop, output = TRUE) {
  # Output if variable is TRUE
  if (output == TRUE) {
    for (i in 1:numloop) {
      # Print Hello World
      cat("Hello World", i, "\n")  
    }
  } else {
    cat("output is not TRUE", "\n")  
  }
}

hello(8, output = TRUE)

Python

string = "Hello World"
print(string)

Python Function

# Define function hello with parameter string
def hello(string):                       # Function header
    """Prints a string"""                # Description
    
    # Print string
    print(string)                        # Body

# Call hello
hello("Hello World (generated with Python Function)")

Python Function with Loop

# Define function hello for printing Hello World n-times (if output = TRUE)
def hello(numloop, output = True):
    """Prints Hello World n-times"""

    # If Output is true
    if output is True:
       # Loop
       for i in range(numloop):
           # Print string
           print("Hello World", i+1)
    else:
       print("Output is not TRUE")

# Call hello
hello(8, output = True)

hello-world's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.