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