BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello

Let's say that in vector parameter we have 5 arguments:

current month+previous month+last DEC+same month previous year+last month previous quarter

 

Sometimes some arguments are same.

for example:

current month=1807

previous month=1806

last DEC=1712

same month previous year=1707

last month previous quarter=1806

vector=1807+1806+1712+1707+1806;

 

How can I tell sas that in case that there are identical arguments in &vector parameter to  leave only one of them.

so I want that    vector=1807+1806+1712+1707;;

 

7 REPLIES 7
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Store data in a dataset, then use Base SAS datasteps and procedures to manipulate data.  This is the fundamental of SAS programming.

Ronein
Onyx | Level 15

Thank you.

You are telling me to store the information in data set and then take distinct values.

But ,I get the data in parameter as I showed so we need to search for solution  from here.

There is no data set.

How can I create a data set from information in parameter?

 

PaigeMiller
Diamond | Level 26

Read it into a data set. Then manipulate it.

--
Paige Miller
Kurt_Bremser
Super User
data quarters (keep=quarter);
length quarter $4;
do i = 1 to countw("&param","+");
  quarter = scan("&param",i,"+");
  output;
end;
run;

and you got a nice dataset from which to work.

Ronein
Onyx | Level 15

So now from the &vector parameter I created a data set.

Then I took the distinct values.

Now I need to create again a parameter with multiple values with + between them

I should I do the final step please?

%let vector=1807+1806+1712+1806;

data tbl1 (keep=YYMM);
length YYMM $4;
do i = 1 to countw("&vector","+");
  YYMM = scan("&vector",i,"+");
  output;
end;
run;

PROC SQL;
	create table tbl2 as
	select 	 distinct YYMM  
	from tbl1
;
QUIT;

/*Now I want to create a parameter called  &vector2 that will get the values in table tbl2 with + symbol between values*/
Kurt_Bremser
Super User

If you kept your data in a small dataset (which is the sensible thing to do) instead of a macro variable (which is usually not the smartest thing to do - I'm being polite here!), you'd only need a sort nodupkey or a select distinct.

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
  • 7 replies
  • 1881 views
  • 7 likes
  • 4 in conversation