BookmarkSubscribeRSS Feed
BrahmanandaRao
Lapis Lazuli | Level 10
/*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;




13 REPLIES 13
PaigeMiller
Diamond | Level 26

You want us to take the exam for you?

--
Paige Miller
BrahmanandaRao
Lapis Lazuli | Level 10

i want answers please

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
BrahmanandaRao
Lapis Lazuli | Level 10

I tried and get few solutions please help

BrahmanandaRao
Lapis Lazuli | Level 10
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;
BrahmanandaRao
Lapis Lazuli | Level 10

PLEASE  CHECK I EDITED

Kurt_Bremser
Super User

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.

Tom
Super User Tom
Super User

First part is not too bad.  Things to worry about. 

  • What about ! as delimiter?
  • You did not define the length for VAR2.  Do you know what length SAS will pick for it?  Are you sure it will long enough.
  • Do you really want VAR2 to start with a space?

 

Spoiler

 

var2=left(scan((VAR1,2,'?.!'));

 

For the second one you don't seem to have followed the requirements. 

  • They want two variables NUM and LYRICS. 
  • They seem to only want those two variables.
  • Do you really want to include the ! in the last LYRICS value?

 

Spoiler

 

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

 

 

BrahmanandaRao
Lapis Lazuli | Level 10
3, 4, 5 Questions solutions please
Kurt_Bremser
Super User

#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 

 

ballardw
Super User

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 13 replies
  • 2268 views
  • 0 likes
  • 5 in conversation