Lab Exercise – SAS programming | My Assignment Tutor

1CopyrightWarningThis material has been reproduced and communicated to you by or on behalf ofFederation University Australia in accordance with Section 113P of the Copyright Act1968 (the Act).The material in this communication may be subject to copyright under the Act. Anyfurther reproduction or communication of this material may be the subject of copyrightprotection under the Act.Do not remove this notice.ITECH3101 –Business Analytics and Decision Supportweek 9Lab Exercise – SAS programming -3 Using SAS function and ArrayID: Name: __________Project 1: Knowing functions other than character functionsThe SAS programming language has a rich assortment of functions that can greatlysimplify some complex programming problems. We summarize some useful facts aboutSAS functions:• All SAS function names are followed by zero or more arguments.• Arguments to SAS functions can be variables, constants, expressions or even otherfunctions.• Functions can only return a single values and , in most cases, the arguments to SASfunctions do not change after the function is executed.1. MISSING functionThe MISSING function returns a value of true (1) if the argument is a missing value andfalse (0) otherwise. Argument of this function can be a character or numeric value.2ExampleIn above code, missing function tests if age is a missing value. If so, we assign a missingvalue to the variable age_group.After clicking Run tap, we get:2. INPUT and PUT functions3INPUT function performs character-to-numeric conversion, and PUT function performsnumeric-to-character conversion.IINPUT function performs character-to-numeric conversion. Its first argument is acharacter value, typically a character variable, and its second argument is the informatyou want to use to associate with the first argument.Example4In above code, double-trailing @@ symbol ” holds the line strongly.” In other words, thereading pointer will move to the next record only if there are no more data values to beread on a line. Use the retain statement when you want SAS to preserve a variable’s valuefrom the previous iteration of the DATA step. In this program, we want to read datavalues that may either represent groups (‘A’ or ‘B’) or numeric scores. Because we don’tknow if we’ll be reading a character or a number, we read very value as a character andtest if it is an ‘A’ or a ‘B’. If not, we assume it is a score and use the INPUT function toconvert the character variable to numeric. In the statement score = input(test,5.);, the firstargument test includes a character such as 45, the second argument the informat (5.) islarger than we need ( only need 2.). However, INPUT function will not read past the endof a character value, so there is no harm in choosing a large number for the numericinformat.After clicking Run tap, we get:PUT function performs numeric-to-character conversion. Its first argument is a numericor character value, and its second argument is the format( either a built-in SAS format orone that you wrote). PUT function takes the first argument, formats it using the secondargument, and assigns the result to a character value.Example5In above code, we use PROC FORMAT to create own formats. The FORMATprocedure creates formats that will later be associated with variables in a FOTMATstatement. The procedure starts with statement PROC FORMAT and continues with oneor more VALUE statement:PROC FORMAT;VALUE name range-1 = ‘formatted-text-1’range-2 = ‘formatted-text-2’..;where name must start with a $ if the format is for character data. Each range is the valueof a variable that is assigned to the text given in quotation marks on the right side of theequal sign.In this example, we have a data about age and create a format that places the ages intofour groups. The variable age4 is character variable with values of ‘1’,’2′,’3′, or ‘4’.After clicking Run tap, we get:63. LAG and DIF functionsThe LAG (lagged) function returns the value of its argument the last time the functionexecuted. If we execute the LAG function for every iteration of DATA step, it returnsthe value of its argument from previous observation. In SAS, we may want to compare adata value from a current observation with a value form a previous observation and mayalso want to look back several observations.Example7In above code, the variable up_down will be the current day’s price minus the price fromthe previous day because the program is executing LAG function for every iteration ofDATA step.After clicking Run tap, we get:8DIF (X) function is equal to X – LAG(X). We can substitute the line on the aboveprogram with up-down = dif(price);4. Arithmetic and mathematical functionsSome of the more common arithmetic and mathematical functions and their purposes arelisted below: Function nameActionLOGBase e logLOG10Base 10 logSINSine of he argument(in radians)COSCosine (in radians)TANTangent(in radians)INTDrops the fractional part of a numberSQRTSquare root Example9In above code, the program creates a new variable called loglos that is natural log of los(length of staying in hospital). loglos will be written in data set func_eg and its valueswill be the natural (base e) log of los.After clicking Run tap, we get:10Project 2: Character functionsIn this project, we discuss some functions that deal with character values.1. LENGTHE and LENGTHC functionsLENGTHN function returns the length of a character value, not counting trailing blanks.If the argument is a missing value, the function returns a 0. LENGTHC function returnsthe storage length of a character variable.ExampleAfter clicking Run tap, we get:11In above code, the variable string is assigned a length of 5 and the variable miss isassigned a length of 4. The lengthn function returns a 3, the length of string with the(2)trailing blanks removed. The storage length shows that string has a length of 5. Thelengthn function returns a length of 0 for the variable miss while lengthc returns thestorage length (4).2. COMPRESS function- Remove characters from a stringThe COMPRESS function can remove any number of specified characters from acharacter variable. With the ‘k’ modifier, we can use this function to extractcharacters( for example, all digits ) from a string. This is one of the most powerfulcharacter functions in the SAS. If we provide only one argument( a character value), thisfunction removes blanks from the string. An optional second argument is a string ofcharacters that we ant to remove from the first argument.12Some of more useful modifiers are: ModifierDescription‘a’All upper- and lowercase letters‘d’All digits‘p’All punctuation(such as periods, commas,etc‘s’All whitespace characters(spaces, tabs.linefeeds, carriage returns)‘i’Ignore case‘k’Keep the specified characters; remove allothers( very useful) Examplestring1=’abc def 123′; string2='(908) 782-1234′; string3=’120 Lbs.’;(1) compress (string1)= abcdef123Because there is only one argument, compress function removes all blanks.(2) compress(string1,’0123456789′) = abc defThe second argument are removed.(3)compress(string1,,’d’)= abc defUsing two commas tells the function that ‘d’ is the third argument(modifier) and you wantto remove all digits. Note that using one comma means that ‘d’ is the second argumentand you are trying to remove all ‘d’ from the string.(4) compress(string2,,’kd’)= 9087821234This keeps digits and throws everything else away.3. Character data verificationWe sometimes want to be sure that only certain values are present in a character variable.In this case, we can use VERIFY function to test if there are any invalid characterspresent.13After clicking Run tap, we get:14In above code, only the values ‘A’,’B’,’C’,’D’, and ‘E’ are valid data values. To verify data,the VERIFY function inspects every character in the first argument, and if it finds anyvalue not in the verify string (the second argument), it will return the position of the firstoffending value. If all the values of the string are located in the verify string, a value of 0is returned. In this program, for the first observation, p will be 0; in the secondobservation, p will be 3; in the third observation, p will be 1 and in the fourth observation,p will be 4.Project 3: Using ArrayIn this project, we work on the usage of array. SAS arrays are good tools that can reducethe amount of coding in a SAS DATA step and save you huge amounts of time.A SAS array is a collection of SAS variables. Using the array name and a subscript, anarray element can represent any one of the variables included in the array.1. Converting all numeric values of 999 to missing valuesIn some applications, we may have certain data on a group of subjects such as age, height,and weight, etc. Missing values may be coded as 999 for each of these variables. In thiscase, we need to convert every value of 999 to a SAS missing value because SAS doesn’ttreat values of 999 as missing values.15In above code, the first iteration of the DO loop is statement: if miss[1] = 999 then miss[1] = .; , which becomes if age = 999 then age = . ;.Once DO loop has finished, each of variables in the array have been processed. As wedon’t need to DO loop counter (i) in the output data set, so we use a DROP statement toremove it from the data set.After clicking Run tap, we get:162. Using temporary arraysTemporary array does not actually refer to a list of variables. In other words, no realvariables are created when you use a temporary array. You can declare an array to betemporary and use the array elements in their subscripted from in DATA step.17In above code, the program uses a temporary array to hold the passing scores on fiveexams. Students’ scores are then read and compared to these passing scores, and thenumber of failed courses is recorded. We define a temporary array pass by using thekeyword _temporary_ following the brackets. pass[1] through pass[5] keep five passinginitial values of scores. The five passing scores are available for comparison to thestudent grades in every iteration of DATA step because values of temporary arrayelements are automatically retained. The array statement array score[5] is equivalent toarray scores[5] score1-score5;. We place an asterisk in the brackets of array score[*] tosave time of counting the number numeric variables in the array.After clicking Run tap, we get:18Project 4. Answering questions (Please do this at your home by using your owncomputer)1 What is the difference between white hat and black hat SEO(Search EngineOptimization) activities?2. A data set (MANY) contains the variables X1-X5,Y1-Y5. First, run the followingprogram to create this data set:DATA MANY;INPUT X1-X5 Y1-Y5;DATALINES;1 2 3 4 5 6 7 8 9 103 . 5 . 7 5 . . . 159 8 . . . 4 4 4 4 1;Write a program to include the following in data set MANY:(1) The mean(average) of the X1-X5(call it MEAN_X) and the mean of Y1-Y5( callit MEAN_Y(hint: use MEAN function such as MEAN(OF X1-X5)(2) The minimum value of X1-X5(call it MIN_X) and the minimum value of Y1-Y5(call it MIN_Y)(hint: use MIN function such as MIN(OF X1-X5)).3. Describe and explain the structure of a typical internet search engine194. What were the challenges, the proposed solution, and the obtained results for IGNcompany to increase search traffic?Project 5. Creating a Professional ReportSummarize the above experiments procedure, results, answering questions andscreenshots (project 1, 2, 3, 4) into one report. Your report is the assignment that isrequired to be submitted for evaluation on week 11. Create a report by following belowsteps.You can add a chapter called Chapter 9 in your previous report.1. Open your last week’s report and find the end of last week’s report.2. Copy this week’s related experimental results, your findings and Screenshots, andpaste them at the end of last week’s report.3. Delete original Table of Content you created.4. Select all content , align all text to both left and right margin5. Use shortcut key approach, generate Chapter 9: SAS programming -3 UsingSAS function and Array6. Then use shortcut key approach to generate proper sub-chapters for this week’slab work.7. Insert Table of Contents to your report.

GET HELP WITH YOUR HOMEWORK PAPERS @ 25% OFF

For faster services, inquiry about  new assignments submission or  follow ups on your assignments please text us/call us on +1 (251) 265-5102

Write My Paper Button

WeCreativez WhatsApp Support
We are here to answer your questions. Ask us anything!
👋 Hi, how can I help?
Scroll to Top