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

I want check wheather exsiting in the dataset, then preform PROC SQL insert into table.

 

For example check if month 2017-08 not exsiting then

 Proc SQL;

 Insert into table ...

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Are you trying to check for a value in a column, if it doesn't exist insert a new row with the value?

Or are you trying to create a new variable? 

 

If its the first look af an UPDATE statement instead. 

View solution in original post

3 REPLIES 3
Reeza
Super User

Are you trying to check for a value in a column, if it doesn't exist insert a new row with the value?

Or are you trying to create a new variable? 

 

If its the first look af an UPDATE statement instead. 

Patrick
Opal | Level 21

@JHE

Something like below could do.

data master;
  origin='Master';
  format myDateVar date9.;

  myDateVar='01Aug2017'd;
  do i=1 to 10;
    output;
  end;
run;

data trans;
  format myDateVar date9.;
  origin='Trans';

  i=11;
  myDateVar='05Aug2017'd;
  output;

  i=12;
  myDateVar='01Sep2017'd;
  origin='Trans';
  output;
run;

%let max_month='01Jan1960'd;
proc sql noprint;
  select name into:varlist separated by ','
  from dictionary.columns where libname='WORK' and memname='MASTER' order by varnum
  ;
  select max(intnx('month',myDateVar,0,'b')) into :max_month
  from master
  ;
  insert into master
  select &varlist
  from trans
  where intnx('month',myDateVar,0,'b') > &max_month
  ;
quit;

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
  • 3 replies
  • 3164 views
  • 2 likes
  • 3 in conversation