BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
baystanil
Calcite | Level 5

Hi there,

below is code to get ParkType, as Monument or Park.

data np_summary2;
    set pg1.np_summary;
    ParkType=scan(parkname,-1);
    keep Reg Type ParkName ParkType;
run;

 I would be interested to see ParkType, as National Monument or National Park.

How to do it using SCAN or other function?

I can created separate two column and then concatenate, but would want simple or short way to do the same.

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi, take a look at the data in pg1.np_summary:

Cynthia_sas_0-1595428646926.png

 



Assuming that the word "National" is next to the last piece of ParkName, which it is in these records, then this code would do what you're asking:

data np_summary_alt;
set pg1.np_summary;
ParkType=catx(' ',scan(parkname,-2),scan(parkname,-1));
keep Reg Type ParkName ParkType;
run;

proc print data=np_summary_alt(obs=10);
run;

You can scan and concatenate without creating 2 new variables.

 

Hope this helps,
Cynthia

View solution in original post

2 REPLIES 2
Cynthia_sas
SAS Super FREQ

Hi, take a look at the data in pg1.np_summary:

Cynthia_sas_0-1595428646926.png

 



Assuming that the word "National" is next to the last piece of ParkName, which it is in these records, then this code would do what you're asking:

data np_summary_alt;
set pg1.np_summary;
ParkType=catx(' ',scan(parkname,-2),scan(parkname,-1));
keep Reg Type ParkName ParkType;
run;

proc print data=np_summary_alt(obs=10);
run;

You can scan and concatenate without creating 2 new variables.

 

Hope this helps,
Cynthia

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

LIBNAME 101

Follow along as SAS technical trainer Dominique Weatherspoon expertly answers all your questions about SAS Libraries.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 1094 views
  • 1 like
  • 2 in conversation