BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Justin9
Obsidian | Level 7

Hi,

 

I've got a variable called 'concat' (character variable). Please can someone provide some code that would help me to just keep all values of 'concat' which doesn't have 202406 in it i.e. keep first 15 records and remove last three records in my dataset?

 

Concat

202401_Base

202401_Medium

202401_High

202402_Base

202402_Medium

202402_High

202403_Base

202403_Medium

202403_High

202404_Base

202404_Medium

202404_High

202405_Base

202405_Medium

202405_High

202406_Base

202406_Medium

202406_High

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Here you go:

data demo;
  input concat :$20.;
/*  if index(concat, '202406') ne 1;*/
  if scan(concat,1,'_') ne '202406';
  datalines;
202401_Base
202401_Medium
202401_High
202402_Base
202402_Medium
202402_High
202403_Base
202403_Medium
202403_High
202404_Base
202404_Medium
202404_High
202405_Base
202405_Medium
202405_High
202406_Base
202406_Medium
202406_High
;

Btw: If you copy/paste your question including the sample data as is into an AI tool like chatGPT or copilot then you will likely get valid code.

View solution in original post

3 REPLIES 3
Astounding
PROC Star
If the date always appears at the beginning of CONCAT, subsetting is easy:
data want;
set have;
if concat =: "202406" then delete;
run;
If 202406 might appear in the middle of CONCAT instead of the beginning, it is only slightly more complex. Which is it?
Patrick
Opal | Level 21

Here you go:

data demo;
  input concat :$20.;
/*  if index(concat, '202406') ne 1;*/
  if scan(concat,1,'_') ne '202406';
  datalines;
202401_Base
202401_Medium
202401_High
202402_Base
202402_Medium
202402_High
202403_Base
202403_Medium
202403_High
202404_Base
202404_Medium
202404_High
202405_Base
202405_Medium
202405_High
202406_Base
202406_Medium
202406_High
;

Btw: If you copy/paste your question including the sample data as is into an AI tool like chatGPT or copilot then you will likely get valid code.

Justin9
Obsidian | Level 7
Thanks for your help!

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 3 replies
  • 698 views
  • 0 likes
  • 3 in conversation