Iterate over a custom set in SAS

Franyá

First of all, apologize for my poor english but that's because I'm not native. I'm a newbie in SAS programming too, and I need someone to help me with this problem struggling me. I have one dataset A containing a numeric field YM representing year and month (e.g., 200902) that I'm using to filter the dataset. In particular, I want to get N filtered datasets using N differents values YM.

  • A_filtered_200901 = A.filter(YM == 200901)
  • A_filtered_200902 = A.filter(YM == 200902)
  • A_filtered_200903 = A.filter(YM == 200903)
  • ...

My idea was to generate the sequence of YM used to filter and then give it as an argument to a %macro containing a PROC SQL. In code/pseucode:

data ym_dataset;
    date = input(put(20090201, 8.), yymmdd8.);
    do i = 1 to 3;
        aux1 = intnx('MONTH', date, i);
        aux2 = put(aux1, yymmddn8.);
        list_of_ym_values = substr(aux2 , 1, 6);
        output;
    end;
run;

%macro my_macro(list_of_ym_values);
    proc sql;
    %do i = 1 %to dim(&list_of_ym_values)
      select * 
      from A 
      where YM = &list_of_ym_values(i)
    %end        
    quit;
%mend my_macro;

%my_macro(ym_dataset[list_of_ym_values])

I know that this is not the correct approach, but I hope that someone could shed me some light about doing it properly.

Thank you!!

Kiran

you need loop through list of variables and this values can be created in a macro variable. But as @richard suggested in comments is not great idea to split datasets.

 /* create macrovariable with all values*/  
proc sql;
select list_of_ym_values into :List
 separated by "|" from ym_dataset;
%put &list;

/* scan through each variable and create new dataset*/
 %macro one;
 %do i=1 %to %sysfunc(countw(&list),"|") ;
 %let val= %scan(&list,&i,|);
proc sql;
create table want_&val as
select * from ym_dataset
where list_of_ym_values = "&val";
%end;
 %mend;
%one;

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Iterate over template int

分類Dev

Unable to iterate over an ElementArrayFinder

分類Dev

C - Linux - Custom kernel module to iterate over a process' children blows up kernel log and the computer

分類Dev

How to iterate over and filter an array?

分類Dev

iterate over unique values in PANDAS

分類Dev

iterate over GroupBy object in dask

分類Dev

how to iterate over tuple items

分類Dev

How to iterate over the lines in a string?

分類Dev

Iterate over a tensor dimension in Tensorflow

分類Dev

How to iterate over dates in a dataframe?

分類Dev

Dynamically iterate over static information

分類Dev

How to iterate over block of text

分類Dev

Iterate/enumerate over part of a list?

分類Dev

Iterate over each object In array

分類Dev

Jersey howto iterate over parameters?

分類Dev

How do I write a custom induction rule over a parameterized inductive set?

分類Dev

How to iterate in order for a custom map?

分類Dev

Iterate over cell versions on BigTable row

分類Dev

Is there a way to iterate over a slice in reverse in Go?

分類Dev

java iterate over map except last iteration

分類Dev

How can we iterate over an HashMap in JSTL?

分類Dev

How to define and iterate over map in Jenkinsfile

分類Dev

iterate over certain columns in data frame

分類Dev

How to iterate over keys of a generic object in TypeScript?

分類Dev

Iterate Over Files in Variable Path (Bash)

分類Dev

In Elm, how can I iterate over a map?

分類Dev

Flutter firebase database iterate over items

分類Dev

How to iterate over a dictionary and operate with its elements?

分類Dev

Using for_each to iterate over form inputs

Related 関連記事

ホットタグ

アーカイブ