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

Hi,

 

I encountered a weired situation. I imported a dataset from CSV files, and named it MIDAS. Most of its variables have format BEST12. and informat 12.

 

I processed it as usual and when I tried to merge it to another dataset, with "if a and b" specified, the resultant dataset has 0 observation. This is unexpected, because I mannually checked that there are many observations with the same "by" variable values. 

 

So I suspected that it was because the format. I tried to use this to remove all format:

 

proc datasets lib=work memtype=data nolist;
modify MIDAS;
attrib _all_ label=' ';
attrib _all_ format=;
attrib _all_ informat=;
run;
quit;

 

However, it does not work. Then I tried to remove format of dates and the rest using

"format date YYMMDDN8.;
informat date YYMMDD6.;"

 

This time it seems to be working. But once when I opened the reformated dataset, I repeatedly hear "beep" and in the log I got many many "ERROR: There was a problem with the format so BEST. was used."

 

What should I do to make the merge work? Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

The actual SAS format applied to variables will never have an effect on SET or Merge.

 

You mention errors. It helps to provide the actual errors and code from the log. Paste into a code box using the forum {i} menu icon.

 

I suspect from " I imported a dataset from CSV " that you actually used Proc Import or the import wizard or similar task. Each time you use Proc Import SAS is guessing from the contents of the file what type and format the variables should have. I suspect that you actually have some variables that are character instead of numeric in the different sets. This can happen if the first few rows of the data are missing for a variable then SAS will set it to character.

 

What is best with CSV files is to run the import one time. SAS will generate data step code that you can copy from the log into an editor and save. Check that the variable types, informats and lengths are as you need. Save the program. Then the next time you read a CSV of the same format you change the infile information and the data set name. All of the variables will have the same name, type, length and format.

It helps to add variable labels as well.

 

View solution in original post

1 REPLY 1
ballardw
Super User

The actual SAS format applied to variables will never have an effect on SET or Merge.

 

You mention errors. It helps to provide the actual errors and code from the log. Paste into a code box using the forum {i} menu icon.

 

I suspect from " I imported a dataset from CSV " that you actually used Proc Import or the import wizard or similar task. Each time you use Proc Import SAS is guessing from the contents of the file what type and format the variables should have. I suspect that you actually have some variables that are character instead of numeric in the different sets. This can happen if the first few rows of the data are missing for a variable then SAS will set it to character.

 

What is best with CSV files is to run the import one time. SAS will generate data step code that you can copy from the log into an editor and save. Check that the variable types, informats and lengths are as you need. Save the program. Then the next time you read a CSV of the same format you change the infile information and the data set name. All of the variables will have the same name, type, length and format.

It helps to add variable labels as well.

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1 reply
  • 3782 views
  • 0 likes
  • 2 in conversation