/*2) Given the following alphanumeric variable VAR1 :*/
VAR1 = "Is this the real life? Is this just fantasy? Caught in a landslide. No escape from reality!" ;
/*a) Keep only the second sentence Is this just fantasy in VAR2*/
/*b) Count the number of words (character strings) separated by blanks in VAR3*/
/*c) Write a DATA step that gives this result table*/
NUM LYRICS
1 Is this the real life
2 Is this just fantasy
3 Caught in a landslide
4 No escape from reality
5
/*3) Which of the following pieces of code cannot exist in any SAS program ?*/
a) systask command "ps -e | grep sas" shell wait ;
b) filename ps_cmd pipe "ps -e | grep sas" ;
c) x "ps -e | grep sas" ;
d) proc unix cmd="ps -e | grep sas" out=res ; This is not exist SAS program
e) %sysexec(ps -e | grep sas) ;
/*4) Which of the following statement is FALSE regarding the Pass-Through method ?*/
a) You are free to specify or not a schema as a connection parameter False
b) You can use any SAS function in the query sent to the target database
c) The query sent by pass-through is executed by the target database system and not by SAS
d) You can use pass-through with Oracle, SQL Server, ODBC drivers and many others database systems
/*5) From SASHELP.CLASS for Exercise 1, we create a new dataset and 3 indexes as follow :*/
data class ;
set sashelp.class ;
run ;
proc sql ;
create index SEX on class (SEX) ;
create index NAME on class (NAME) ;
create index HEIGHT on class (HEIGHT) ;
quit ;
/*Will the following WHERE clauses will take benefit of one of the index ? Which one ?*/
WHERE clause INDEX used ?
where SEX eq "M"
where SEX eq "M" or SEX eq "F"
where NAME eq "Alfred"
where NAME in ("Alfred","Alice")
where NAME eq "Alfred" or NAME eq "Alice"
where NAME like "A%"
where substr(NAME,2,1) eq "l"
where upcase(NAME) eq "JOHN"
where HEIGHT between 55 and 60
where floor(HEIGHT) eq 62
where HEIGHT - 1 gt 60
ANSWERS
data nn;
VAR1 = "Is this the real life? Is this just fantasy? Caught in a landslide. No escape from reality!" ;
r=scan(VAR1,2,'?');
run;
data nn;
VAR1 = "Is this the real life? Is this just fantasy? Caught in a landslide. No escape from reality!" ;
r=scan(VAR1,2,'?');
q=countw(VAR1,,'S');
run;
data s;
VAR1 = "Is this the real life? Is this just fantasy? Caught in a landslide. No escape from reality!" ;
count=countw(VAR1,'?.');
do i =1 to count ;
new =scan(VAR1,i, '?.');
output;
end;
run;
You want us to take the exam for you?
i want answers please
So your answer is YES, you want us to take the test for you. This is unacceptable.
Please put some effort into answering these questions yourself. If your code doesn't work, then we can help you.
I tried and get few solutions please help
data nn;
VAR1 = "Is this the real life? Is this just fantasy? Caught in a landslide. No escape from reality!" ;
VAR2=scan(VAR1,2,'?');
VAR3=countw(VAR1,,'S');
run;
data s;
VAR1 = "Is this the real life? Is this just fantasy? Caught in a landslide. No escape from reality!" ;
count=countw(VAR1,'?.');
do i =1 to count ;
NUMLYRICS=scan(VAR1,i, '?.');
output;
end;
run;
In the exam, you are asked to create VAR2. I do not see that anywhere in your code.
PLEASE CHECK I EDITED
Don't look so bad.
Your second code should be
data s;
VAR1 = "Is this the real life? Is this just fantasy? Caught in a landslide. No escape from reality!" ;
count = countw(VAR1,'?.');
do NUM = 1 to count;
LYRICS = scan(VAR1,NUM,'?.');
output;
end;
keep NUM LYRICS;
run;
Rethink your answer to question 4.
First part is not too bad. Things to worry about.
var2=left(scan((VAR1,2,'?.!'));
For the second one you don't seem to have followed the requirements.
data s;
VAR1 = "Is this the real life? Is this just fantasy? Caught in a landslide. No escape from reality!" ;
do NUM =1 to countw(VAR1,'?.!');
LYRICS=left(scan(VAR1,num, '?.!'));
output;
end;
keep num lyrics;
run;
Obs NUM LYRICS 1 1 Is this the real life 2 2 Is this just fantasy 3 3 Caught in a landslide 4 4 No escape from reality
#3 looks OK
In #4, c is positively true. What does that tell you about the other answers?
For #5, study How SAS Selects an Index for WHERE Processing in Using an Index for WHERE Processing
This exact question has been asked on the forum before.
Just one of the threads: https://communities.sas.com/t5/SAS-Programming/Count-words/m-p/753521#M237506 check the OP post history for the rest the pieces
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.