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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 872 views
  • 1 like
  • 2 in conversation