//
archives

# Archive for

### Apples and Friends Puzzle

##### The Puzzle:

You have a basket containing ten apples. You have ten friends, who each desire an apple. You give each of your friends one apple.
Now all your friends have one apple each, yet there is an apple remaining in the basket.
How?

### Weighing 10 Bags Puzzle

##### The Puzzle:

You have 10 bags full of coins, in each bag are 1,000 coins. But one bag is full of forgeries, and you can’t remember which one. But you do know that a genuine coins weigh 1 gram, but forgeries weigh 1.1 grams. To hide the fact that you can’t remember which bag contains forgeries, you plan to go just once to the central weighing machine to get ONE ACCURATE weight. How can you identify the bag with the forgeries with just one weighing? And what if you didn’t know how many bags contain forgeries?

### Try if you can solve :

Data details. It is a free text field so user has given more than one Email address with various delimiter like space, comma, semicolon, colon and other. Below is the sample of values stored:-

Can you help me to extract Email address and store it delimited by semicolon only to other variable?

### Try if you can :

Required Output : Raw data :

1) Economics – [Gen= 64%] [OBC= 59%] [SC= 54%] [ST= 54%] [PWD= 54%]

2) Political Science – [Gen= 62%] [OBC= 58%] [SC= 53%] [ST= 53%] [PWD= 54%]

3) Philosophy – [Gen= 65%] [OBC= 61%] [SC= 57%] [ST= 56%] [PWD= 56%]

4) Psychology – [Gen= 64%] [OBC= 58%] [SC= 54%] [ST= 55%] [PWD= 55%]

5) Sociology – [Gen= 65%] [OBC= 60%] [SC= 56%] [ST= 56%] [PWD= 55%]

6) History – [Gen= 63%] [OBC= 59%] [SC= 54%] [ST= 54%] [PWD= 56%]

7) Anthropology – [Gen= 65%] [OBC= 60%] [SC= 58%] [ST= 57%] [PWD= 57%]

8) Commerce – [Gen= 62%] [OBC= 57%] [SC= 53%] [ST= 52%] [PWD= 54%]

9) Education – [Gen= 63%] [OBC= 59%] [SC= 55%] [ST= 53%] [PWD= 55%]

10) Social Work – [Gen= 63%] [OBC= 59%] [SC= 56%] [ST= 55%] [PWD= 55%]

11) Defence and Strategic Studies – [Gen= 68%] [OBC= 62%] [SC= 60%] [ST= 59%] [PWD= 56%]

12) Home Science – [Gen= 62%] [OBC= 56%] [SC= 54%] [ST= 54%] [PWD= 53%]

14) Public Administration – [Gen= 65%] [OBC= 61%] [SC= 58%] [ST= 56%] [PWD= 53%]

15) Population Studies – [Gen= 64%] [OBC= 60%] [SC= 55%] [ST= 56%] [PWD= 55%]

16) Music – [Gen= 62%] [OBC= 57%] [SC= 54%] [ST= 51%] [PWD= 54%]

17) Management – [Gen= 63%] [OBC= 58%] [SC= 55%] [ST= 54%] [PWD= 55%]

18) Maithili – [Gen= 73%] [OBC= 64%] [SC= 54%] [ST= 54%] [PWD= 64%]

19) Bengali – [Gen= 61%] [OBC= 57%] [SC= 53%] [ST= 51%] [PWD= 52%]

20) Hindi – [Gen= 67%] [OBC= 62%] [SC= 58%] [ST= 57%] [PWD= 58%]

21) Kannada – [Gen= 67%] [OBC= 63%] [SC= 61%] [ST= 62%] [PWD= 58%]

22) Malayalam – [Gen= 62%] [OBC= 58%] [SC= 56%] [ST= 50%] [PWD= 54%]

23) Odia – [Gen= 67%] [OBC= 63%] [SC= 60%] [ST= 60%] [PWD= 57%]

24) Punjabi – [Gen= 60%] [OBC= 56%] [SC= 52%] [ST= %] [PWD= 53%]

25) Sanskrit – [Gen= 67%] [OBC= 62%] [SC= 58%] [ST= 58%] [PWD= 58%]

26) Tamil – [Gen= 62%] [OBC= 59%] [SC= 56%] [ST= 55%] [PWD= 56%]

27) Telugu – [Gen= 63%] [OBC= 60%] [SC= 56%] [ST= 57%] [PWD= 56%]

28) Urdu – [Gen= 61%] [OBC= 57%] [SC= 51%] [ST= 52%] [PWD= 55%]

29) Arabic – [Gen= 68%] [OBC= 63%] [SC= 50%] [ST= 57%] [PWD= 60%]

30) English – [Gen= 62%] [OBC= 57%] [SC= 53%] [ST= 52%] [PWD= 55%]

31) Linguistics – [Gen= 65%] [OBC= 60%] [SC= 56%] [ST= 55%] [PWD= 53%]

32) Chinese – [Gen= 64%] [OBC= 56%] [SC= 51%] [ST= 55%] [PWD= 51%]

33) Dogri – [Gen= 68%] [OBC= 53%] [SC= 52%] [ST= 48%] [PWD= %]

34) Nepali – [Gen= %] [OBC= 48%] [SC= 42%] [ST= %] [PWD= 45%]

35) Manipuri – [Gen= 63%] [OBC= 53%] [SC= 52%] [ST= 45%] [PWD= 48%]

36) Assamese – [Gen= 63%] [OBC= 59%] [SC= 56%] [ST= 57%] [PWD= 52%]

37) Gujarati – [Gen= 60%] [OBC= 55%] [SC= 54%] [ST= 53%] [PWD= 47%]

38) Marathi – [Gen= 54%] [OBC= 52%] [SC= 50%] [ST= 48%] [PWD= 47%]

39) French – [Gen= 66%] [OBC= 61%] [SC= 54%] [ST= 50%] [PWD= 56%]

40) Spanish – [Gen= 67%] [OBC= 60%] [SC= 51%] [ST= 50%] [PWD= 46%]

41) Russian – [Gen= 69%] [OBC= 66%] [SC= 54%] [ST= 49%] [PWD= %]

42) Persian – [Gen= 67%] [OBC= 62%] [SC= 57%] [ST= 55%] [PWD= 58%]

43) Rajasthani – [Gen= 67%] [OBC= 63%] [SC= 58%] [ST= 58%] [PWD= 57%]

44) German – [Gen= 69%] [OBC= 63%] [SC= 56%] [ST= 52%] [PWD= 49%]

45) Japanese – [Gen= 64%] [OBC= 55%] [SC= 55%] [ST= %] [PWD= %]

46) Adult Education – [Gen= 69%] [OBC= 64%] [SC= 61%] [ST= 63%] [PWD= 62%]

47) Physical Education – [Gen= 63%] [OBC= 58%] [SC= 56%] [ST= 54%] [PWD= 54%]

49) Arab Culture and Islamic Studies – [Gen= 69%] [OBC= 65%] [SC= 52%] [ST= 52%] [PWD= 57%]

50) Indian Culture – [Gen= 70%] [OBC= 65%] [SC= 58%] [ST= 57%] [PWD= 59%]

55) Labour Welfare – [Gen= 64%] [OBC= 59%] [SC= 56%] [ST= 57%] [PWD= 55%]

58) Law – [Gen= 63%] [OBC= 59%] [SC= 55%] [ST= 54%] [PWD= 55%]

59) Library and Information Science – [Gen= 62%] [OBC= 58%] [SC= 54%] [ST= 53%] [PWD= 53%]

60) Buddhist, Jaina, Gandhian and Peace Studies – [Gen= 69%] [OBC= 64%] [SC= 60%] [ST= 62%] [PWD= 57%]

62) Comparative Study of Religions – [Gen= 64%] [OBC= 60%] [SC= 57%] [ST= 56%] [PWD= 55%]

63) Mass Communication and Journalism – [Gen= 58%] [OBC= 54%] [SC= 51%] [ST= 53%] [PWD= 52%]

65) Performing Arts – Dance – [Gen= 63%] [OBC= 59%] [SC= 55%] [ST= 54%] [PWD= 50%]

66) Museology & Conservation – [Gen= 66%] [OBC= 61%] [SC= 54%] [ST= 54%] [PWD= 50%]

67) Archaeology – [Gen= 68%] [OBC= 64%] [SC= 59%] [ST= 59%] [PWD= 55%]

68) Criminology – [Gen= 68%] [OBC= 63%] [SC= 58%] [ST= 56%] [PWD= 57%]

70) Tribal and Regional Language – [Gen= 63%] [OBC= 60%] [SC= 58%] [ST= 58%] [PWD= 56%]

71) Folk Literature – [Gen= 65%] [OBC= 58%] [SC= 52%] [ST= 56%] [PWD= 46%]

72) Comparative Literature – [Gen= 64%] [OBC= 52%] [SC= 46%] [ST= 48%] [PWD= %]

73) Sanskrit Traditional Subjects – [Gen= 62%] [OBC= 57%] [SC= 50%] [ST= 52%] [PWD= 55%]

74) Women Studies ** – [Gen= 65%] [OBC= 60%] [SC= 57%] [ST= 55%] [PWD= 58%]

79) Visual Arts – [Gen= 59%] [OBC= 56%] [SC= 53%] [ST= 52%] [PWD= 52%]

80) Geography – [Gen= 64%] [OBC= 59%] [SC= 55%] [ST= 55%] [PWD= 54%]

81) Social Medicine & Community Health – [Gen= 64%] [OBC= 60%] [SC= 58%] [ST= 54%] [PWD= 55%]

82) Forensic Science – [Gen= 64%] [OBC= 60%] [SC= 57%] [ST= 55%] [PWD= 50%]

83) Pali – [Gen= 70%] [OBC= 67%] [SC= 64%] [ST= 53%] [PWD= 50%]

84) Kashmiri – [Gen= 56%] [OBC= 48%] [SC= %] [ST= %] [PWD= %]

85) Konkani – [Gen= 56%] [OBC= 50%] [SC= 52%] [ST= %] [PWD= %]

87) Computer Science and Applications – [Gen= 60%] [OBC= 55%] [SC= 51%] [ST= 53%] [PWD= 50%]

88) Electronic Science – [Gen= 63%] [OBC= 59%] [SC= 57%] [ST= 56%] [PWD= 57%]

89) Environmental Sciences – [Gen= 60%] [OBC= 56%] [SC= 52%] [ST= 52%] [PWD= 51%]

90) International and Area Studies – [Gen= 65%] [OBC= 62%] [SC= 57%] [ST= 57%] [PWD= 55%]

91) Prakrit – [Gen= 70%] [OBC= 63%] [SC= 52%] [ST= 42%] [PWD= %]

92) Human Rights and Duties – [Gen= 66%] [OBC= 61%] [SC= 57%] [ST= 56%] [PWD= 55%]

93) Tourism Administration and Management – [Gen= 60%] [OBC= 56%] [SC= 53%] [ST= 54%] [PWD= 49%]

94) Bodo – [Gen= 62%] [OBC= %] [SC= 51%] [ST= 58%] [PWD= 55%]

95) Santali – [Gen= 65%] [OBC= 61%] [SC= %] [ST= 60%] [PWD= 57%]

### Copying SAS Data Sets between Hosts

Introduction:

Proc copy is used to copy or move data from one library to another library.

Feature:

1. It can use to move all data from one library to another.

2. It can also use to move particular dataset from particular library to another.

3. It also can be use to move one particular data type also.

Syntax:

If any help reply me back….

### Conditional deleting observation from a dataset

If we are talking about splitting data, one of the proven method will be Hash, very efficient(one pass to the data if presorted, no need to know how many ‘types’ in advance) and fully dynamic.

data have;

input type   x   y;

cards;

1 12 13

1 14 15

1 12 13

2 14 25

2 15 26

2 26 23

3 25 26

3 26 35

3 36 38

;

data _null_;

declare hash h();

h.definekey(‘_n_’);

h.definedata(‘type’, ‘x’, ‘y’);

h.definedone();

do _n_=1 by 1 until (last.type);

set have;

by type;

rc=h.replace();

end;

rc=h.output(dataset:cats(‘want’,type));

run;

### PROC OPTIONS

##### System options are global instructions that affect the entire SAS session and control the way SAS performs operations. SAS system options differ from SAS data set options and statement options in that once you invoke a system option, it remains in effect for all subsequent data and proc steps in a SAS job, unless you specify them.

In order to view which options are available and in effect for your SAS session, use proc options.

`PROC OPTIONS;RUN;`

Here is some sample output produced by the proc options statement above.

`PORTABLE OPTIONS: NOCAPS            Translate quoted strings and titles to upper case? CENTER            Center SAS output? DATE              Date printed in title? ERRORS=20         Maximum number of observations with error messages FIRSTOBS=1        First observation of each data set to be processed FMTERR            Treat missing format or informat as an error? LABEL             Allow procedures to use variable labels? LINESIZE=96       Line size for printed output MISSING=.         Character printed to represent numeric missing values NOTES             Print SAS notes on log? NUMBER            Print page number on each page of SAS output? OBS=MAX           Number of last observation to be processed PAGENO=1          Resets the current page number on the print file PAGESIZE=54       Number of lines printed per page of output PROBSIG=0         Number of significant figures guaranteed when printing P-values REPLACE           Allow replacement of permanent SAS data sets? SOURCE            List SAS source statements on log? NOSOURCE2         List included SAS source statements on log? YEARCUTOFF=1900   Cutoff year for DATE7. informat`

Not every SAS system option is listed above, but many of the most common options are listed. Of course, it is not necessary to understand every SAS option in order to run a SAS job. This module will discuss some of the more common SAS system options that the typical user would use to customize their SAS sessions.

###### Log, output and procedure options

Log, output and procedure options specify the ways in which SAS output is written to the SAS log and procedure output file.

Below are some commonly used log, output, and procedure options:

center controls whether SAS procedure output is centered. By default, output is always centered. To specify not centered, use nocenter, which will print results to the output window as left justified.

date prints the date and time to the log and output window. By default, the date and time is always printed. To suppress the printing of the date, usenodate.
label allows SAS procedures to use labels with variables. By default, labels are permitted. To suppress the printing of labels, use nolabel.

notes controls whether notes are printed to the SAS log. By default, notes are printed. To suppress the printing of notes, use nonotes.

number controls whether page numbers are printed on the first title line of each page of printed output. By default, page numbers are printed. To suppress the printing of page numbers, use nonumber.

linesize= specifies the line size (printer line width) for the SAS log and the SAS procedure output file used by the data step and procedures.

pagesize= specifies the number of lines that can be printed per page of SAS output.
missing= specifies the character to be printed for missing numeric variable values.
formchar= specifies the list of graphics characters that define table boundaries.

Below is sample syntax for setting some of these options.

`OPTIONS NOCENTER NODATE NONOTES LINESIZE=80 MISSING=.         FORMCHAR = '|----|+|---+=|-/<>*';`
###### SAS data set control options

SAS data set control options specify how SAS data sets are input, processed, and output.

Below are some commonly used SAS data set control options:

firstobs= causes SAS to begin reading at a specified observation in a data set. If SAS is processing a file of raw data, this option forces SAS to begin reading at a specified line of data. The default is firstobs=1.

obs= specifies the last observation from a data set or the last record from a raw data file that SAS is to read. To return to using all observations in a data set use obs=all replace specifies whether permanently stored SAS data sets are to be replaced. By default, the SAS system will over-write existing SAS data sets if the SAS data set is re-specified in a data step. To suppress this option, use noreplace.

Below is sample syntax for invoking some of these options.

`OPTIONS OBS=100 NOREPLACE;`
###### Error handling options

Error handling options specify how the SAS System reports on and recovers from error conditions.

Below are two commonly used error handling options:

errors= controls the maximum number of observations for which complete error messages are printed. The default maximum number of complete error messages is errors=20

fmterr (which is in effect by default if not specified) controls whether the SAS System generates an error message when the system cannot find a format to associate with a variable. Turning this option off is useful when you have a SAS system data set with custom formats, but you do not have the corresponding SAS format library. In this situation, SAS will generate an ERROR message for every unknown format it encounters and will terminate the SAS job without running any following data and proc steps. Thus, in order to override this default option and read a SAS system data set without requiring a SAS format library, use nofmterr

Below is sample syntax for invoking these options.

`OPTIONS ERRORS=100 NOFMTERR;RUN;`
###### Reading and writing data options

Reading and writing data options control the ways in which data are input to, and output from, the SAS system.

Below are some commonly used reading and writing data options:caps specifies whether lowercase characters input to the SAS System are translated to uppercase. The default is nocaps.

probsig= controls the number of significant digits of p-values in some statistical procedures.

yearcutoff= specifies the first year of a 100-year span used as the default by various informats and functions. (For more information, see Using dates in SAS).

Below is sample syntax for invoking these options.

`OPTIONS CAPS PROBSIG=3 YEARCUTOFF=1900;`

It should also be noted that these data set options are global options, as opposed to local data set options that are specified within a data or procstep, and remain in effect until the data or proc step ends. For more on local data set options, such as obs, keep and drop, see Subsetting data in SAS

### Type the letter of the word or phrase on the right that completes the statements with given option as “descriptor portion, data portion, compilation & execution”.

1. When you submit a DATA step, SAS processes the
step in the __________________ phase first.

2. When you submit a DATA step, SAS processes the
step in the __________________ phase second.

3. During the compilation phase, SAS creates the
_____________ of the output data set.

4. During the execution phase, SAS creates the
_____________ of the output data set.

### Calculate a person’s age

``````/* Create sample data */

data birth;
input name \$ bday :mmddyy10.;
datalines;
Miguel      12/31/1973
Joe         02/28/1976
Rutger      03/29/1976
Broguen     03/01/1976
Susan       12/12/1976
Michael     02/14/1971
LeCe        11/09/1967
Hans        07/02/1955
Lou         07/30/1960
;

/* Use the INTCK function to count the number of months between       */
/* the date of birth and the current date.  Divide the number of      */
/* months by 12 to produce the number of years.  Use the MONTH        */
/* function to determine if the month of the birthday and the current */
/* date are the same.  If they are, determine if the birthday has     */
/* occurred this year.  If it hasn't, adjust the age by subtracting   */
/* one year.                                                          */

data ages;
set birth;
retain current;
if _n_=1 then current=today();
format bday current worddate20.;
age=int(intck('month',bday,current)/12);
if month(bday)=month(current) then age=age-(day(bday)>day(current));
run;

proc print;
run;``````

### Comparing a row in a dataset with the next row

SAS has the LAG function to look backwards as LinusH pointed out. However there is no looking forward function. But you can kind of simulate this using a second SET statement with the POINT= option so that you will read the I+1 observation, you will need to rename the variables from the second SET statement, so that you can compare. Taking your logic here is some sample code.

data have;
infile cards dlm=”,”;
input
Patient_ID : 8.
Disch_Date : anydtdtm.
Facility_Type : \$32.
;
cards;
12345,02JAN2014:00:00:00.000,05JAN2014:00:00:00.000,Nursing Home
12345,05JAN2014:00:00:00.000,07JAN2014:00:00:00.000,Hospital
23456,02JAN2014:00:00:00.000,06JAN2014:00:00:00.000,Nursing Home
23456,06JAN2014:00:00:00.000,09JAN2014:00:00:00.000,Hospital
23456,08JAN2014:00:00:00.000,11JAN2014:00:00:00.000,Nursing Home
23456,11JAN2014:00:00:00.000,19JAN2014:00:00:00.000,Hospital
23456,19JAN2014:00:00:00.000,23JAN2014:00:00:00.000,Nursing Home
23456,24JAN2014:00:00:00.000,25JAN2014:00:00:00.000,Hospital
23456,25JAN2014:00:00:00.000,30JAN2014:00:00:00.000,Nursing Home
34567,09JAN2014:00:00:00.000,15JAN2014:00:00:00.000,Nursing Home
45678,13JAN2014:00:00:00.000,20JAN2014:00:00:00.000,Nursing Home
;
data want;
obs1 = 1;
do while( obs1 <= nobs);
set have nobs=nobs;
obs2 = obs1 + 1;
set
have(
rename=(
Patient_ID = pId2
Disch_Date = dd2
Facility_Type = ft2
)
) point=obs2
;
If pId2 = Patient_ID and
ft2 = “Hospital” and
Facility_Type = “Nursing Home” and