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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 2437 views
  • 2 likes
  • 3 in conversation